# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
757478 | Nika533 | Snowball (JOI21_ho_t2) | C++14 | 2 ms | 632 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
string s;
void test_case() {
cin>>n>>m;
int arr[n+1];
map<int,int> mymap;
for (int i=1; i<=n; i++) {
cin>>arr[i];
}
int b[m+1];
b[0]=0;
int mx=0;
int mn=0;
set<int> myset;
for (int i=1; i<=m; i++) {
cin>>b[i];
b[i]+=b[i-1];
//cout<<i<<" "<<b[i]<<" B"<<endl;
if (b[i]>mx) {
mx=b[i];
int num=b[i]-mn;
myset.insert(num);
mymap[num]=mn;
//cout<<"B1 "<<num<<" "<<mn<<endl;
}
if (b[i]<mn) {
mn=b[i];
int num=mx-b[i];
myset.insert(num);
mymap[num]=mx;
//cout<<"B2 "<<num<<" "<<mx<<endl;
}
}
vector<int> ans(n+1,0);
for (int i=1; i<n; i++) {
// i --- i+1
int dist=arr[i+1]-arr[i];
set<int> :: iterator it=myset.lower_bound(dist);
if (it==myset.end()) {
ans[i]+=mx;
ans[i+1]+=-mn;
continue;
}
int num=mymap[*it];
//cout<<"AAA"<<i<<" "<<i+1<<" "<<*it<<" "<<num<<endl;
if (num>0) {
ans[i]+=num;
ans[i+1]+=dist-num;
//cout<<i<<" "<<num<<" "<<dist-num<<endl;
}
else {
num=-num;
ans[i+1]+=num;
ans[i]+=dist-num;
//cout<<i<<" "<<dist-num<<" "<<num<<endl;
}
}
ans[1]+=-mn;
ans[n]+=mx;
for (int i=1; i<=n; i++) {
cout<<ans[i]<<" ";
}
cout<<endl;
}
main () {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
T=1;
while (T--) {
test_case();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |