#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 500005
#define int long long
const int INF = 1e9 + 7;
int x[N], l[N];
int32_t main(){
//fileio();
fastio();
int n;
cin>>n;
for (int i = 1; i <= n; i++){
cin>>x[i];
}
for (int i = 1; i <= n; i++){
cin>>l[i];
}
vector<int> v(n, 0);
iota(v.begin(), v.end(), 1);
sort(v.begin(), v.end(), [&](int a, int b){
if (x[a] == x[b]) return l[a] < l[b];
return x[a] < x[b];
});
int sum = 0;
int ans = 0;
multiset<pii> maks;
for (auto i : v){
if (sum <= l[i]){
sum += x[i];
ans++;
maks.insert({l[i] + x[i], x[i]});
continue;
}
int tmp = 0;
auto it = maks.rbegin();
while(it != maks.rend() && it->st + tmp >= sum + x[i]){
tmp += it->nd;
it++;
if (sum <= l[i] + tmp){
sum += x[i];
ans++;
maks.insert({l[i] + x[i], x[i]});
break;
}
}
}
//cout<<endl;
cout<<ans<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2516 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
12096 KB |
Output is correct |
2 |
Correct |
126 ms |
12112 KB |
Output is correct |
3 |
Correct |
147 ms |
12112 KB |
Output is correct |
4 |
Correct |
127 ms |
12112 KB |
Output is correct |
5 |
Correct |
127 ms |
12240 KB |
Output is correct |
6 |
Correct |
136 ms |
13380 KB |
Output is correct |
7 |
Correct |
118 ms |
12364 KB |
Output is correct |
8 |
Correct |
127 ms |
13140 KB |
Output is correct |
9 |
Correct |
126 ms |
13376 KB |
Output is correct |
10 |
Correct |
125 ms |
14148 KB |
Output is correct |
11 |
Correct |
178 ms |
26260 KB |
Output is correct |
12 |
Correct |
163 ms |
28820 KB |
Output is correct |
13 |
Correct |
175 ms |
28404 KB |
Output is correct |
14 |
Correct |
165 ms |
28756 KB |
Output is correct |
15 |
Correct |
190 ms |
30016 KB |
Output is correct |
16 |
Correct |
159 ms |
16464 KB |
Output is correct |
17 |
Correct |
143 ms |
17552 KB |
Output is correct |
18 |
Correct |
133 ms |
17984 KB |
Output is correct |
19 |
Correct |
129 ms |
15952 KB |
Output is correct |
20 |
Correct |
133 ms |
14144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2516 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2616 KB |
Output is correct |
26 |
Correct |
3 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2652 KB |
Output is correct |
28 |
Correct |
3 ms |
2608 KB |
Output is correct |
29 |
Correct |
3 ms |
2652 KB |
Output is correct |
30 |
Correct |
3 ms |
2652 KB |
Output is correct |
31 |
Correct |
5 ms |
2652 KB |
Output is correct |
32 |
Correct |
5 ms |
2652 KB |
Output is correct |
33 |
Correct |
5 ms |
2848 KB |
Output is correct |
34 |
Correct |
6 ms |
3152 KB |
Output is correct |
35 |
Correct |
5 ms |
2780 KB |
Output is correct |
36 |
Correct |
8 ms |
2648 KB |
Output is correct |
37 |
Correct |
9 ms |
2812 KB |
Output is correct |
38 |
Correct |
8 ms |
2652 KB |
Output is correct |
39 |
Correct |
8 ms |
2652 KB |
Output is correct |
40 |
Correct |
8 ms |
2652 KB |
Output is correct |
41 |
Correct |
12 ms |
2816 KB |
Output is correct |
42 |
Correct |
12 ms |
2908 KB |
Output is correct |
43 |
Correct |
12 ms |
2912 KB |
Output is correct |
44 |
Correct |
12 ms |
2912 KB |
Output is correct |
45 |
Correct |
14 ms |
2880 KB |
Output is correct |
46 |
Correct |
15 ms |
2908 KB |
Output is correct |
47 |
Correct |
15 ms |
2948 KB |
Output is correct |
48 |
Correct |
17 ms |
2908 KB |
Output is correct |
49 |
Correct |
19 ms |
2900 KB |
Output is correct |
50 |
Correct |
18 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2516 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
132 ms |
12096 KB |
Output is correct |
22 |
Correct |
126 ms |
12112 KB |
Output is correct |
23 |
Correct |
147 ms |
12112 KB |
Output is correct |
24 |
Correct |
127 ms |
12112 KB |
Output is correct |
25 |
Correct |
127 ms |
12240 KB |
Output is correct |
26 |
Correct |
136 ms |
13380 KB |
Output is correct |
27 |
Correct |
118 ms |
12364 KB |
Output is correct |
28 |
Correct |
127 ms |
13140 KB |
Output is correct |
29 |
Correct |
126 ms |
13376 KB |
Output is correct |
30 |
Correct |
125 ms |
14148 KB |
Output is correct |
31 |
Correct |
178 ms |
26260 KB |
Output is correct |
32 |
Correct |
163 ms |
28820 KB |
Output is correct |
33 |
Correct |
175 ms |
28404 KB |
Output is correct |
34 |
Correct |
165 ms |
28756 KB |
Output is correct |
35 |
Correct |
190 ms |
30016 KB |
Output is correct |
36 |
Correct |
159 ms |
16464 KB |
Output is correct |
37 |
Correct |
143 ms |
17552 KB |
Output is correct |
38 |
Correct |
133 ms |
17984 KB |
Output is correct |
39 |
Correct |
129 ms |
15952 KB |
Output is correct |
40 |
Correct |
133 ms |
14144 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
2 ms |
2652 KB |
Output is correct |
43 |
Correct |
2 ms |
2652 KB |
Output is correct |
44 |
Correct |
2 ms |
2652 KB |
Output is correct |
45 |
Correct |
2 ms |
2616 KB |
Output is correct |
46 |
Correct |
3 ms |
2652 KB |
Output is correct |
47 |
Correct |
3 ms |
2652 KB |
Output is correct |
48 |
Correct |
3 ms |
2608 KB |
Output is correct |
49 |
Correct |
3 ms |
2652 KB |
Output is correct |
50 |
Correct |
3 ms |
2652 KB |
Output is correct |
51 |
Correct |
5 ms |
2652 KB |
Output is correct |
52 |
Correct |
5 ms |
2652 KB |
Output is correct |
53 |
Correct |
5 ms |
2848 KB |
Output is correct |
54 |
Correct |
6 ms |
3152 KB |
Output is correct |
55 |
Correct |
5 ms |
2780 KB |
Output is correct |
56 |
Correct |
8 ms |
2648 KB |
Output is correct |
57 |
Correct |
9 ms |
2812 KB |
Output is correct |
58 |
Correct |
8 ms |
2652 KB |
Output is correct |
59 |
Correct |
8 ms |
2652 KB |
Output is correct |
60 |
Correct |
8 ms |
2652 KB |
Output is correct |
61 |
Correct |
12 ms |
2816 KB |
Output is correct |
62 |
Correct |
12 ms |
2908 KB |
Output is correct |
63 |
Correct |
12 ms |
2912 KB |
Output is correct |
64 |
Correct |
12 ms |
2912 KB |
Output is correct |
65 |
Correct |
14 ms |
2880 KB |
Output is correct |
66 |
Correct |
15 ms |
2908 KB |
Output is correct |
67 |
Correct |
15 ms |
2948 KB |
Output is correct |
68 |
Correct |
17 ms |
2908 KB |
Output is correct |
69 |
Correct |
19 ms |
2900 KB |
Output is correct |
70 |
Correct |
18 ms |
2904 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
1 ms |
2396 KB |
Output is correct |
73 |
Correct |
210 ms |
21688 KB |
Output is correct |
74 |
Correct |
199 ms |
21696 KB |
Output is correct |
75 |
Correct |
241 ms |
21584 KB |
Output is correct |
76 |
Correct |
203 ms |
21568 KB |
Output is correct |
77 |
Correct |
203 ms |
21584 KB |
Output is correct |
78 |
Execution timed out |
2039 ms |
24540 KB |
Time limit exceeded |
79 |
Halted |
0 ms |
0 KB |
- |