#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=1e18;
int main(){
int n,q;
cin>>n>>q;
vector<ll> x;
for(int i=0;i<n;i++){
ll a; cin>>a;
x.push_back(a);
}
vector<ll> nie;
nie.push_back(MAX);
for(int i=0;i<n-1;i++){
nie.push_back(x[i+1]-x[i]);
}
nie.push_back(MAX);
vector<ll> nl,nr,he;
for(int i=0;i<n;i++){
nl.push_back(x[i]);
nr.push_back(x[i]);
he.push_back(0);
}
while(q--){
ll a; cin>>a;
bool sw=0;
if(a>0) sw=1;
if(a==0) continue;
for(int i=0;i<n;i++){
int id=i+sw;
x[i]+=a;
if(nie[id]==0) continue;
if(sw){
// cout<<i<<": "<<x[i]<<" "<<nr[i]<<endl;
if(x[i]>nr[i]){
ll aux=min(x[i]-nr[i],nie[id]);
nr[i]=x[i];
he[i]+=aux;
nie[id]-=aux;
if(i==n-1) nie[id]=MAX;
}
}
else{
if(x[i]<nl[i]){
ll aux=min(nl[i]-x[i],nie[id]);
nl[i]=x[i];
he[i]+=aux;
nie[id]-=aux;
if(i==0) nie[id]=MAX;
}
}
}
}
for(int i=0;i<n;i++) cout<<he[i]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
14 ms |
424 KB |
Output is correct |
5 |
Correct |
14 ms |
432 KB |
Output is correct |
6 |
Correct |
14 ms |
428 KB |
Output is correct |
7 |
Correct |
17 ms |
436 KB |
Output is correct |
8 |
Correct |
15 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
420 KB |
Output is correct |
10 |
Correct |
9 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
14 ms |
332 KB |
Output is correct |
16 |
Correct |
14 ms |
440 KB |
Output is correct |
17 |
Correct |
12 ms |
428 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
14 ms |
424 KB |
Output is correct |
5 |
Correct |
14 ms |
432 KB |
Output is correct |
6 |
Correct |
14 ms |
428 KB |
Output is correct |
7 |
Correct |
17 ms |
436 KB |
Output is correct |
8 |
Correct |
15 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
420 KB |
Output is correct |
10 |
Correct |
9 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
14 ms |
332 KB |
Output is correct |
16 |
Correct |
14 ms |
440 KB |
Output is correct |
17 |
Correct |
12 ms |
428 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
82 ms |
2308 KB |
Output is correct |
21 |
Correct |
85 ms |
2176 KB |
Output is correct |
22 |
Correct |
138 ms |
1940 KB |
Output is correct |
23 |
Correct |
931 ms |
1892 KB |
Output is correct |
24 |
Execution timed out |
2577 ms |
2072 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |