#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n;
cin >> n;
vector<pair<int,pair<int,int>>>a(n+1);
for(int i = 1;i<=n;i++)
{
cin >> a[i].second.first;
}
for(int i = 1;i<=n;i++)
{
cin >> a[i].second.second ;
a[i].first = a[i].second.first + a[i].second.second;
}
sort(a.begin(),a.end());
vector<vector<int>>dp(n+1,vector<int>(n+1,1e15+5));
dp[0][0] = 0;
for(int i =1;i<=n;i++)
{
dp[i][0] = 0;
}
for(int i = 1;i<=n;i++)
{
for(int j = 1 ;j<=n;j++)
{
if(dp[i-1][j-1] <= a[i].second.second ) dp[i][j] = min(dp[i-1][j-1]+a[i].second.first, dp[i-1][j]);
else dp[i][j] = dp[i-1][j];
}
}
int ans = 0;
for(int i =1;i<=n;i++)
{
if(dp[n][i] < 1e15+5)ans = i;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
878 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
146 ms |
190280 KB |
Output is correct |
22 |
Correct |
151 ms |
193292 KB |
Output is correct |
23 |
Correct |
159 ms |
191820 KB |
Output is correct |
24 |
Correct |
154 ms |
192304 KB |
Output is correct |
25 |
Correct |
151 ms |
192356 KB |
Output is correct |
26 |
Correct |
150 ms |
190316 KB |
Output is correct |
27 |
Correct |
153 ms |
194632 KB |
Output is correct |
28 |
Correct |
157 ms |
188856 KB |
Output is correct |
29 |
Correct |
155 ms |
192464 KB |
Output is correct |
30 |
Correct |
153 ms |
195912 KB |
Output is correct |
31 |
Correct |
151 ms |
195400 KB |
Output is correct |
32 |
Correct |
149 ms |
190024 KB |
Output is correct |
33 |
Correct |
147 ms |
192796 KB |
Output is correct |
34 |
Correct |
157 ms |
194636 KB |
Output is correct |
35 |
Correct |
154 ms |
193864 KB |
Output is correct |
36 |
Correct |
139 ms |
194892 KB |
Output is correct |
37 |
Correct |
142 ms |
191008 KB |
Output is correct |
38 |
Correct |
133 ms |
189768 KB |
Output is correct |
39 |
Correct |
136 ms |
193376 KB |
Output is correct |
40 |
Correct |
136 ms |
191032 KB |
Output is correct |
41 |
Correct |
157 ms |
194940 KB |
Output is correct |
42 |
Correct |
135 ms |
191056 KB |
Output is correct |
43 |
Correct |
134 ms |
190928 KB |
Output is correct |
44 |
Correct |
135 ms |
193608 KB |
Output is correct |
45 |
Correct |
134 ms |
191832 KB |
Output is correct |
46 |
Correct |
148 ms |
195736 KB |
Output is correct |
47 |
Correct |
136 ms |
192324 KB |
Output is correct |
48 |
Correct |
138 ms |
191860 KB |
Output is correct |
49 |
Correct |
151 ms |
190280 KB |
Output is correct |
50 |
Correct |
154 ms |
192784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Runtime error |
878 ms |
1048576 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |