Submission #08646


ソースコード

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
44
45
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int total,n,count=0,l=0;
cin >> total >> n;
int mana[n];
int kind[n];
for(int i=0;i<n;i++){
cin >> mana[i] >> kind[i];
}
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1-i;j++){
if(mana[j]>mana[j+1]){
swap(mana[j],mana[j+1]);
swap(kind[j],kind[j+1]);
}
}
}
for(int i=0;i<n;i++){
if(total>mana[i] && kind[i]!=0){
count++;
total=total-mana[i];
kind[i]--;
}
}
while(1){
if(total < mana[l]) break;
if(mana[l]<=total && kind[l]!=0){
count++;
total=total-mana[l];
kind[l]--;
}
if(kind[l]==0){
l++;
}
}
cout << total << " " << count << endl;
return(0);
}

ステータス

項目 データ
問題 0051 - お菓子
ユーザー名 ei1612
投稿日時 2016-08-17 13:33:05
言語 C++11
状態 Accepted
得点 10
ソースコード長 790 Byte
最大実行時間 28 ms
最大メモリ使用量 684 KB

セット

セット 得点 Cases
1 ALL 10 / 10 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
sample1_in.txt AC 28 ms 472 KB
1
sample1_in2.txt AC 17 ms 452 KB
1
sample1_in3.txt AC 21 ms 684 KB
1
sample1_in4.txt AC 17 ms 656 KB
1