Submission #27543


ソースコード

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
46
#include<stdio.h>
typedef struct{
int cost;
int n;
}okashi;
int main(){
okashi o[15],temp;
int n,x;
int ans=0;
int i,j;
scanf("%d %d",&x,&n);
for(i=0;i<n;i++){
scanf("%d %d",&o[i].cost,&o[i].n);
}
for(i=0;i<n-1;i++){
for(j=0;j<n-1-i;j++){
if(o[j].cost>o[j+1].cost){
temp=o[j];
o[j]=o[j+1];
o[j+1]=temp;
}
}
}
for(i=0;i<n;i++){
if(x>=o[i].cost){
x-=o[i].cost;
o[i].n--;
ans++;
}
else
break;
}
i=0;
while(1){
if(x>=o[i].cost&&o[i].n>0){
ans++;
x-=o[i].cost;
o[i].n--;
}
if(o[i].n==0)
i++;
if(x==0||x<o[i].cost)
break;
}
printf("%d %d\n",x,ans);
}

ステータス

項目 データ
問題 0051 - お菓子
ユーザー名 ei1710
投稿日時 2017-10-08 08:40:00
言語 C
状態 Accepted
得点 10
ソースコード長 917 Byte
最大実行時間 32 ms
最大メモリ使用量 408 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
sample1_in.txt AC 32 ms 380 KB
1
sample1_in2.txt AC 20 ms 408 KB
1
sample1_in3.txt AC 16 ms 368 KB
1
sample1_in4.txt AC 19 ms 392 KB
1