PersonalCorpus 版 (精华区)

//51861 2006 sino@HIT Accepted (0.14s 365K +10+0) 811 Bytes C++ 
//2004-03-30 00:00:52
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int cmp_int(const void *a, const void *b)
{
    if (*(int *)a<*(int *)b) return -1; else if (*(int *)a>*(int *)b) return 1; else return 0;
}

int main()
{
    int c[1001][2],i,j,k,n,a,b,queue[11],total;
    bool flag;

    while (scanf("%d",&n)==1) {
        for (i=0;i<n;i++) scanf("%d%d",&c[i][1],&c[i][0]);
        qsort(c,i,8,cmp_int);
        memset(queue,0,sizeof(queue));
        c[n][0]=2147483647;
        a=c[0][0];
        total=0;
        i=0;
        do {
            for (;i<n && a>=c[i][0];) queue[c[i++][1]]++;
            flag=false;
            for (j=0;j<=10;j++) if (queue[j]) {
                flag=true;
                b=a+j-c[i][0];
                queue[j]--;
                if (b<=0) {
                    a+=j;
                    total+=a;
                } else {
                    queue[b]++;
                    a=c[i][0];
                }
                break;
            }
            if (!flag) a=c[i][0];
        } while (i<n || flag);
        printf("%d\n",total);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.283毫秒