Submission #27532
ソースコード
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 | #include<bits/stdc++.h> #define F first #define S second using namespace std; typedef pair< int , int > Data; int main(){ int x,n,cnt=0; scanf ( "%d %d" ,&x,&n); Data snack[n]; for ( int i=0;i<n;++i){ scanf ( "%d %d" ,&snack[i].F,&snack[i].S); } sort(snack,snack+n); for ( int i=0;i<n;++i){ if (x-snack[i].F>=0){ cnt++; x-=snack[i].F; snack[i].S--; } } for ( int i=0;i<n;++i){ int temp=x/snack[i].F; if (temp){ if (temp>snack[i].S) temp=snack[i].S; cnt+=temp; x-=(snack[i].F)*temp; } else break ; } printf ( "%d %d\n" ,x,cnt); return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0051 - お菓子 |
ユーザー名 | Wonder /*ei1741*/ |
投稿日時 | 2017-10-06 19:42:37 |
言語 | C++11 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 900 Byte |
最大実行時間 | 40 ms |
最大メモリ使用量 | 716 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 10 / 10 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
sample1_in.txt | AC | 40 ms | 480 KB |
1
|
sample1_in2.txt | AC | 20 ms | 716 KB |
1
|
sample1_in3.txt | AC | 20 ms | 560 KB |
1
|
sample1_in4.txt | AC | 22 ms | 664 KB |
1
|