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 pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define PI 3.141592
#define fo(i,n) for (int i=0;i<n;i++)
#define fofo(i,n,j,m) for (int i=0;i<n;i++) for (int j=0;j<m;j++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N=2e5+5,mod=1e9+7;
ll n,q,a[N],w[N],acu,tam[N];
ll X[N],Y[N];
vector<pair<ll,ll>> group; // sortear por fi
ll res[N];
int main() {
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio();
cin >> n >> q;
fo(i,n)
cin >> a[i];
fo(i,q)
cin >> w[i];
ll x,y;
x=y=0;
fo(i,q) {
acu += w[i];
if (acu < x) x = acu;
if (acu > y) y = acu;
tam[i] = abs(x) + abs(y);
X[i] = abs(x);
Y[i] = abs(y);
}
for (int i=0;i<n-1;i++) {
ll p = a[i+1]-a[i];
// tam del seg
// do the bin ?
bool y = false;
for (int j=0;j<q;j++) {
if (tam[j]>=p) {
if (j==0) {
if (w[j]>=0)
res[i] += p;
else res[i+1] += p;
} else {
res[i] += Y[j-1];
res[i+1] += X[j-1];
p -= tam[j-1];
if (w[j]>=0)
res[i] += p;
else
res[i+1] += p;
}
j = q+1;
y = true;
}
}
if (!y) {
res[i] += Y[q-1];
res[i+1] += X[q-1];
}
}
res[0] += X[q-1];
res[n-1] += Y[q-1];
fo(i,n) cout << res[i] << "\n";
return 0;
}
// Recuerda limites
// Recuerda casos especiales
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |