#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii pair<int, int>
#define deb first
#define fin second
#define int long long
using namespace std;
const int N = 5e5, OO = 1e18;
int debs[N], fins[N];
int nBoules, nJours;
inline int getInstant(int delta){
if (delta < 0)
return lower_bound(debs, debs + nJours + 1, -delta) - debs;
else
return upper_bound(fins, fins + nJours + 1, delta) - fins;
}
int boules[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> nBoules >> nJours;
for (int i = 0; i < nBoules; ++i)
cin >> boules[i];
int posCur = 0;
debs[0] = 0; fins[0] = -1;
for (int iJour = 1; iJour <= nJours; ++iJour){
int delta; cin >> delta;
posCur += delta;
debs[iJour] = -min(-debs[iJour - 1], posCur);
fins[iJour] = max(0ll, max(posCur, fins[iJour - 1]));
}
// int debut[nBoules];
for (int iBoule = 0; iBoule < nBoules; ++iBoule){
int gauche = - debs[nJours], droite = 0; //Gauche
if (iBoule != 0)
chmax(gauche, boules[iBoule - 1] - boules[iBoule]);
//in
while (droite > gauche){
int mid = floor((gauche + droite)/double(2));
int moment = getInstant(mid);
if (moment <= nJours && (iBoule == 0 || moment < getInstant(mid + boules[iBoule] - boules[iBoule - 1])))
droite = mid;
else
gauche = mid + 1;
}
// debut[iBoule] = ga
int deb = gauche;
gauche = - 1, droite = fins[nJours];
if (iBoule != nBoules - 1)
chmin(droite, boules[iBoule + 1] - boules[iBoule]);
while (droite > gauche){
int mid = floor((gauche + droite)/double(2)) + 1;
// cout << "dicho " << gauche << " " << droite << " " << mid << endl;
//cout << getInstant(mid, boules[iBoule]) << endl << endl;
int moment = getInstant(mid);
if (moment <= nJours && (iBoule == nBoules - 1 || moment < getInstant(mid + boules[iBoule] - boules[iBoule + 1])))
gauche = mid;
else
droite = mid - 1;
}
cout << gauche - deb + 1 << endl;
// cout << couverts[iBoule].deb << " " << couverts[iBoule].fin << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
17 ms |
332 KB |
Output is correct |
5 |
Correct |
13 ms |
332 KB |
Output is correct |
6 |
Correct |
12 ms |
460 KB |
Output is correct |
7 |
Correct |
12 ms |
460 KB |
Output is correct |
8 |
Correct |
10 ms |
332 KB |
Output is correct |
9 |
Correct |
9 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
16 ms |
388 KB |
Output is correct |
16 |
Correct |
14 ms |
332 KB |
Output is correct |
17 |
Correct |
14 ms |
392 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
17 ms |
332 KB |
Output is correct |
5 |
Correct |
13 ms |
332 KB |
Output is correct |
6 |
Correct |
12 ms |
460 KB |
Output is correct |
7 |
Correct |
12 ms |
460 KB |
Output is correct |
8 |
Correct |
10 ms |
332 KB |
Output is correct |
9 |
Correct |
9 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
16 ms |
388 KB |
Output is correct |
16 |
Correct |
14 ms |
332 KB |
Output is correct |
17 |
Correct |
14 ms |
392 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
32 ms |
3432 KB |
Output is correct |
21 |
Correct |
30 ms |
3380 KB |
Output is correct |
22 |
Correct |
32 ms |
3408 KB |
Output is correct |
23 |
Correct |
60 ms |
3448 KB |
Output is correct |
24 |
Correct |
259 ms |
3724 KB |
Output is correct |
25 |
Correct |
2216 ms |
6560 KB |
Output is correct |
26 |
Correct |
2187 ms |
6524 KB |
Output is correct |
27 |
Correct |
2082 ms |
6316 KB |
Output is correct |
28 |
Correct |
2024 ms |
6332 KB |
Output is correct |
29 |
Correct |
1950 ms |
6184 KB |
Output is correct |
30 |
Correct |
1310 ms |
5740 KB |
Output is correct |
31 |
Correct |
477 ms |
5492 KB |
Output is correct |
32 |
Correct |
385 ms |
5316 KB |
Output is correct |
33 |
Correct |
198 ms |
964 KB |
Output is correct |
34 |
Correct |
2087 ms |
6496 KB |
Output is correct |
35 |
Correct |
2025 ms |
6344 KB |
Output is correct |
36 |
Correct |
2233 ms |
6576 KB |
Output is correct |
37 |
Correct |
2084 ms |
6492 KB |
Output is correct |
38 |
Correct |
2122 ms |
6432 KB |
Output is correct |
39 |
Correct |
2108 ms |
6396 KB |
Output is correct |
40 |
Correct |
1390 ms |
6512 KB |
Output is correct |
41 |
Execution timed out |
2564 ms |
3404 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |