Submission #16764


ソースコード

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>
#include<map>
std::map<int,int> ms[17];
int main(){
int x,n;
scanf("%d %d",&x,&n);
ms[0][0]=x;
for(int i=0;i<n;i++){
int s,m;
scanf("%d %d",&s,&m);
for(int j=n;j>0;j--){
std::map<int,int>::iterator it;
for(it=ms[j-1].begin();it!=ms[j-1].end();it++){
int m1=(*it).first;
int x1=(*it).second;
for(int k=1;k<=m;k++){
int x2=s*k;
if(x1<x2)break;
int m2=m1+k;
int x3=x1-x2;
if((ms[j].find(m2)==ms[j].end())||(ms[j][m2]<x3)){
ms[j][m2]=x3;
}
}
}
//printf("%d ",ms[j].size());
}
//printf("\n");
}
int ans=0,ansx=x;
for(int i=n;i>=0;i++){
if(ms[i].empty()==false){
std::map<int,int>::iterator it=ms[i].end();
it--;
ans=(*it).first;
ansx=(*it).second;
break;
}
}
printf("%d %d\n",ansx,ans);
}

ステータス

項目 データ
問題 0051 - お菓子
ユーザー名 sinapusu2002
投稿日時 2017-05-07 08:39:03
言語 C++11
状態 Accepted
得点 10
ソースコード長 847 Byte
最大実行時間 28 ms
最大メモリ使用量 568 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
sample1_in.txt AC 28 ms 480 KB
1
sample1_in2.txt AC 23 ms 452 KB
1
sample1_in3.txt AC 20 ms 444 KB
1
sample1_in4.txt AC 26 ms 568 KB
1