codeforces586C Gennady the Dentist(模拟)

题目链接:

http://codeforces.com/contest/586/problem/C

题目有些略复杂。。建议看不懂的同学去google翻译一下。。

AC代码:

#include<stdio.h>
typedef long long ll;
ll v[100100],p[100100],d[100100];

ll ans[100100],an;
bool vis[100100];
main(){
    ll n,an=0;
    scanf("%I64d",&n);
    for(int i=1;i<=n;i++){
        scanf("%I64d%I64d%I64d",&v[i],&d[i],&p[i]);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            ans[++an]=i;
            ll ak1=v[i];
            ll ak2=0;
            for(int j=i+1;j<=n;j++){
                if(!vis[j]){
                    p[j]-=ak1+ak2;
                    if(p[j]<0){
                        vis[j]=1;
                        ak2+=d[j];
                    }
                    if(ak1)ak1--;
                }
            }
        }

    }
    printf("%I64d\n",an);
    for(int i=1;i<an;i++){
        printf("%I64d ",ans[i]);
    }
    printf("%I64d\n",ans[an]);
    for(int i=2;i<=n;i++)
        printf("%d ",p[i]);
}


你可能感兴趣的:(codeforces586C Gennady the Dentist(模拟))