#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 300005
#define ii pair<lo int, pair<int, pair<int, pair<int,int> > > >
using namespace std;
int n,m,s,vis[li];
lo int x[li],y[li],total;
priority_queue<ii> q;
unordered_map<lo int ,lo int > tp[li];
int main(){
scanf("%d %d %d",&n,&m,&s);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&x[i],&y[i]);
}
q.push(mp(0,mp(m+s,mp(m,mp(s,0)))));
while(!q.empty()){
ii tmp=q.top();
q.pop();
lo int cst=tmp.fi;
int mm=tmp.se.se.fi;
int ss=tmp.se.se.se.fi;
int ind=tmp.se.se.se.se;
if(tp[ind][mm+ss]>cst) continue;
tp[ind][mm+ss]=cst;
if(ind==n){
total=max(total,cst);
continue;
}
if(mm>0) q.push(mp(cst+x[ind+1],mp(tmp.se.fi-1,mp(mm-1,mp(ss,ind+1)))));
if(ss>0) q.push(mp(cst+y[ind+1],mp(tmp.se.fi-1,mp(mm,mp(ss-1,ind+1)))));
q.push(mp(cst,mp(tmp.se.fi,mp(mm,mp(ss,ind+1)))));
}
printf("%lld\n",total);
return 0;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&n,&m,&s);
~~~~~^~~~~~~~~~~~~~~~~~~~~
school.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&x[i],&y[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
16760 KB |
Output isn't correct |
2 |
Correct |
17 ms |
16884 KB |
Output is correct |
3 |
Correct |
17 ms |
16884 KB |
Output is correct |
4 |
Execution timed out |
2063 ms |
17284 KB |
Time limit exceeded |
5 |
Incorrect |
28 ms |
17284 KB |
Output isn't correct |
6 |
Incorrect |
1938 ms |
17584 KB |
Output isn't correct |
7 |
Execution timed out |
2069 ms |
18480 KB |
Time limit exceeded |
8 |
Execution timed out |
2065 ms |
18480 KB |
Time limit exceeded |
9 |
Execution timed out |
2080 ms |
18480 KB |
Time limit exceeded |
10 |
Execution timed out |
2082 ms |
18480 KB |
Time limit exceeded |
11 |
Execution timed out |
2082 ms |
18480 KB |
Time limit exceeded |
12 |
Execution timed out |
2079 ms |
18480 KB |
Time limit exceeded |
13 |
Execution timed out |
2075 ms |
21756 KB |
Time limit exceeded |
14 |
Execution timed out |
2085 ms |
28860 KB |
Time limit exceeded |
15 |
Execution timed out |
2085 ms |
35452 KB |
Time limit exceeded |
16 |
Execution timed out |
2086 ms |
36992 KB |
Time limit exceeded |
17 |
Execution timed out |
2093 ms |
45196 KB |
Time limit exceeded |
18 |
Execution timed out |
2064 ms |
45748 KB |
Time limit exceeded |
19 |
Execution timed out |
2059 ms |
48420 KB |
Time limit exceeded |
20 |
Execution timed out |
2065 ms |
52828 KB |
Time limit exceeded |