-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp1275.cpp
More file actions
52 lines (46 loc) · 841 Bytes
/
p1275.cpp
File metadata and controls
52 lines (46 loc) · 841 Bytes
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
47
48
49
50
51
52
#include<iostream>
#include<algorithm>
using namespace std;
struct game{
int time;
int value;
};
int cmp(game a,game b){
return a.value>b.value;
}
bool flag[501];
game g[501];
int main(){
int m;
while(cin>>m){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>g[i].time;
flag[i]=true;
}
flag[n]=true;
for(int i=0;i<n;i++){
cin>>g[i].value;
}
sort(g,g+n,cmp);
for(int i=0;i<n;i++){
if(flag[g[i].time]){
flag[g[i].time]=false;
}else{
bool f=false;
for(int j=g[i].time;j>0;j--){
if(flag[j]){
flag[j]=false;
f=true;
break;
}
}
if(!f){
m=m-g[i].value;
}
}
}
cout<<m<<endl;
}
}