CodeRorce- Prizes, Prizes, more Prizes

這個題目比較簡單,但是有些細節。
比如:50個輸入,每個都是10^9,但是獎品最高價格爲5.
那麼獎品5的數量將會超過int的表示範圍,所以cnt要用unsigned long long類型。

#include <stdio.h>
#include <string.h>
typedef unsigned long long LL;
int n;
int points[60];
int cost[5];
LL cnt[5];
LL sum;
int main(){
    freopen("input.txt","r",stdin);

    while(scanf("%d",&n)!=EOF){
        memset(points,0,sizeof(points));
        memset(cost,0,sizeof(cost));
        memset(cnt,0,sizeof(cnt));
        sum=0;
        for (int i = 0; i < n; ++i){
            scanf("%d",&points[i]);
        }
        for (int i = 0; i < 5; ++i)
            scanf("%d",&cost[i]);

        for (int i = 0; i < n; ++i)
        {
            sum+=points[i];
            while(sum>=cost[0]){
                for (int j = 4; j >= 0; --j)
                {
                    int num = sum/cost[j];
                    if (num>=1)
                    {
                        cnt[j]+=num;
                        sum-=cost[j]*num;
                        break;
                    }
                }
            }
        }
        printf("%llu %llu %llu %llu %llu\n",cnt[0],cnt[1],cnt[2],cnt[3],cnt[4]);
        printf("%llu\n",sum);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章