This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
#define int ll
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
ll x[N];
bool L[N], R[N];
int res[N];
void solve(int tc) {
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i ++) {
cin >> x[i];
}
vector<pair<int,int>> vec;
for(int i = 1; i < n; i ++) {
vec.push_back({x[i+1]-x[i], i});
}
sort(all(vec));
int mx = 0, mn = 0, cur = 0;
int it = 0;
for(int i = 1; i <= q; i ++) {
ll w;
cin >> w;
int c1 = cur, mx1 = mx, mn1 = mn;
cur += w;
mx = max(mx, cur);
mn = min(mn , cur);
while(it < vec.size() && mx-mn >= vec[it].F) {
res[vec[it].S] += mx1;
res[vec[it].S+1] -= mn1;
if(w > 0) {
res[vec[it].S] += vec[it].F-mx1+mn1;
}
else {
res[vec[it].S+1] += vec[it].F-mx1+mn1;
}
R[vec[it].S] = 1;
L[vec[it].S+1] = 1;
it ++;
}
}
for(int i = 1; i <= n; i ++) {
if(L[i] == 0) res[i] += -mn;
if(R[i] == 0) res[i] += mx;
cout << res[i] << '\n';
}
}
/*
*/
main() {
ios;
int tt = 1 , tc = 0;
// cin >> tt;
while(tt --) {
solve(++tc);
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve(ll)':
Main.cpp:40:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while(it < vec.size() && mx-mn >= vec[it].F) {
| ~~~^~~~~~~~~~~~
Main.cpp:36:7: warning: unused variable 'c1' [-Wunused-variable]
36 | int c1 = cur, mx1 = mx, mn1 = mn;
| ^~
Main.cpp: At global scope:
Main.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |