Submission #19172
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include<stdio.h> int main(){ int x,n; int i,j,temp; scanf ( "%d %d" ,&x,&n); int s[n],m[n]; int ans=0; for (i=0;i<n;i++){ scanf ( "%d %d" ,&s[i],&m[i]); } for (i=0;i<n;i++){ for (j=0;j<n-i-1;j++){ if (s[j]>s[j+1]){ temp=s[j]; s[j]=s[j+1]; s[j+1]=temp; temp=m[j]; m[j]=m[j+1]; m[j+1]=temp; } } } for (j=0;j<n;j++){ if (x<s[j]){ break ; } x-=s[j]; m[j]--; ans++; } i=0; while (x>=s[i]){ if (m[i]==0){ i++; } else { x-=s[i]; m[i]--; ans++; } } printf ( "%d %d\n" ,x,ans); return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0051 - お菓子 |
ユーザー名 | YUSAKU(ei1718) |
投稿日時 | 2017-06-09 16:24:58 |
言語 | C++11 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 633 Byte |
最大実行時間 | 13 ms |
最大メモリ使用量 | 684 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 10 / 10 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
sample1_in.txt | AC | 10 ms | 476 KB |
1
|
sample1_in2.txt | AC | 13 ms | 460 KB |
1
|
sample1_in3.txt | AC | 10 ms | 572 KB |
1
|
sample1_in4.txt | AC | 13 ms | 684 KB |
1
|