File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+
5+ const int INF = 1e9 + 7 ;
6+
7+ int N, I, G;
8+ int dp[202 ][202 ]{};
9+
10+ int main () {
11+ cin.tie(0)->sync_with_stdio(0);
12+
13+ cin>>N>>I>>G;
14+ for(int i=0;i<=201;i++) for(int j=0;j<=201;j++) dp[i][j] = INF;
15+ dp[0][0] = 0;
16+
17+ for(int i,g;N--;) {
18+ cin>>i>>g;
19+ int ndp[202][202]{};
20+ for(int a=0;a<=201;a++) for(int b=0;b<=201;b++) ndp[a][b] = INF;
21+ for(int a=0;a<=200;a++) for(int b=0;b<=200;b++) if(dp[a][b] != INF) {
22+ int A = min(201, a+i), B = min(201, b+g);
23+ ndp[A][B] = min(ndp[A][B], dp[a][b] + 1);
24+ }
25+ for(int a=0;a<=200;a++) {
26+ if(dp[201][a] != INF) {
27+ int A = min(201, a+g);
28+ ndp[201][A] = min(ndp[201][A], dp[201][a] + 1);
29+ }
30+ if(dp[a][201] != INF) {
31+ int A = min(201, a+i);
32+ ndp[A][201] = min(ndp[A][201], dp[a][201] + 1);
33+ }
34+ }
35+ for(int a=0;a<=201;a++) for(int b=0;b<=201;b++) dp[a][b] = min(dp[a][b], ndp[a][b]);
36+ }
37+
38+ int ans = INF;
39+ for(int i=I;i<=201;i++) for(int j=G;j<=201;j++) ans = min(ans, dp[i][j]);
40+ cout<<(ans == INF ? -1 : ans);
41+
42+ }
43+ ```
You can’t perform that action at this time.
0 commit comments