Submission #934279

#TimeUsernameProblemLanguageResultExecution timeMemory
934279IUA_HasinSnowball (JOI21_ho_t2)C++17
33 / 100
2538 ms5676 KiB
#include <bits/stdc++.h> #define endl "\n" #define finp for(int i=0; i<n; i++) #define fknp for(int k=0; k<n; k++) #define yeap cout<<"YES"<<endl #define nope cout<<"NO"<<endl #define inpintn int n; cin>>n #define inpintarrn int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];} #define inpllarrn long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];} #define ll long long using namespace std; int main () { ll n, q; cin>>n>>q; ll arr[n]; for(int i=0; i<n; i++){ cin>>arr[i]; } if(n==1){ ll w[q]; ll pref[q+1]; pref[0] = 0; for(int i=0; i<q; i++){ cin>>w[i]; pref[i+1] = pref[i] +w[i]; } ll mn = pref[0]; ll mx = pref[0]; for(int i=0; i<q+1; i++){ mn = min(mn, pref[i]); mx = max(mx, pref[i]); } ll ans = 0; if(mn<0){ ans = ans-mn; } if(mx>0){ ans = ans+mx; } // for(int i=0; i<q+1;) // cout<<mn<<endl; // cout<<mx<<endl; cout<<ans<<endl; } else { ll dis[n-1]; for(int i=0; i<n-1; i++){ dis[i] = arr[i+1] - arr[i]; } ll ans[n]; for(int i=0; i<n; i++){ ans[i] = 0; } ll pref[q+1]; pref[0] = 0; ll tt = 1; ll w[q]; while(tt<=q){ cin>>w[tt-1]; pref[tt] = pref[tt-1] + w[tt-1]; tt++; } // cout<<endl; // for(int i=0; i<n-1; i++){ // cout << dis[i] << " "; // } // cout<<endl; // for(int i=0; i<=q; i++){ // cout << pref[i] << " "; // } // cout<<endl; ll a, b; for(int i=0; i<n-1; i++){ a = 0; b = dis[i]; ll l = 0; ll r = dis[i]; for(int j=1; j<=q; j++){ ll c = pref[j]; if(c>0){ ll temp1 = a+c; l = max(temp1, l); l = min(l, r); } else if(c<0){ ll temp2 = b+c; r = min(r, temp2); r = max(l, r); } // cout << l << " " << r << endl; } // cout<<endl; ans[i] += l; ans[i+1] += dis[i]-r; } ll mn = pref[0]; ll mx = pref[0]; for(int i=0; i<q+1; i++){ mn = min(mn, pref[i]); mx = max(mx, pref[i]); } if(mn<0){ ans[0] = ans[0]-mn; } if(mx>0){ ans[n-1] = ans[n-1]+mx; } // cout<<mn<<endl; // cout<<mx<<endl; for(int i=0; i<n; i++){ cout<<ans[i]<<endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...