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 endl '\n'
using namespace std;
const long long MAXN = 2005;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, q;
long long a[MAXN], wind[MAXN];
long long moveleft[MAXN], moveright[MAXN];
void read()
{
cin >> n >> q;
for (long long i = 1; i <= n; ++ i)
cin >> a[i];
long long pos = 0;
for (long long i = 1; i <= q; ++ i)
{
cin >> wind[i];
pos += wind[i];
moveleft[i] = min(pos, moveleft[i-1]);
moveright[i] = max(pos, moveright[i-1]);
}
for (long long i = 1; i <= q; ++ i)
{
moveleft[i] *= -1;
// cout << moveleft[i] << " " << moveright[i] << endl;
}
}
long long ans[MAXN];
void solve()
{
for (long long i = 2; i <= n; ++ i)
{
int f = 0;
for (long long j = 1; j <= q; ++ j)
{
if(a[i-1] + moveright[j] >= a[i] - moveleft[j])
{
// cout << "***" << endl;
// cout << i-1 << " " << i << " " << j << endl;
long long segment = a[i] - a[i-1];
long long to_first = 0, to_second = 0;
if(wind[j] >= 0)
{
to_second = moveleft[j];
to_first = segment - to_second;
}
else
{
to_first = moveright[j];
to_second = segment - to_first;
}
//cout << to_first << " " << to_second << endl;
ans[i-1] += to_first;
ans[i] += to_second;
f = 1;
break;
}
}
if(f == 0)
{
ans[i-1] += moveright[q];
ans[i] += moveleft[q];
}
}
ans[1] += moveleft[q];
ans[n] += moveright[q];
for (long long i = 1; i <= n; ++ i)
cout << ans[i] << " ";
cout << endl;
}
int main()
{
speed();
read();
solve();
return 0;
}
/*
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |