-
Notifications
You must be signed in to change notification settings - Fork 0
/
1998.cpp
75 lines (59 loc) · 1.19 KB
/
1998.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <ios>
using namespace std;
void drop(const vector<int>& sum, int& hold, int k) {
int l = 0;
int r = hold;
while (l + 1 < r) {
int m = (l + r) / 2;
if (sum[hold] - sum[m] <= k) {
r = m;
} else {
l = m;
}
}
hold = l;
}
int main() {
ios::sync_with_stdio(false);
cin.tie();
int n, m, k;
cin >> n >> m >> k;
vector<int> w(n + 1), sum(n + 1);
queue<int> q;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
w[i] = x;
sum[i] = sum[i - 1] + x;
}
for (int i = 1; i <= m; ++i) {
int x;
cin >> x;
q.push(x);
}
int hold = 0;
int t = 0;
while (!q.empty()) {
if (n - hold < q.front() - t) {
t += n - hold;
cout << t << endl;
return 0;
}
t++;
hold += q.front() - t;
t = q.front();
q.pop();
drop(sum, hold, k);
}
cout << t + n - hold << endl;
return 0;
}