Submission #705189

#TimeUsernameProblemLanguageResultExecution timeMemory
705189bin9638Boxes with souvenirs (IOI15_boxes)C++17
100 / 100
527 ms232192 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fs first #define sc second #define N 10000010 #define pb push_back ll sum_left[N],sum_right[N]; ll delivery(int n,int k,int l,int a[]) { for(int i=1;i<=n;i++) if(i<=k) sum_left[i]=a[i-1]+min(a[i-1],l-a[i-1]); else sum_left[i]=sum_left[i-k]+1ll*a[i-1]+min(a[i-1],l-a[i-1]); for(int i=n;i>=1;i--) if(i+k-1>=n) sum_right[i]=l-a[i-1]+min(a[i-1],l-a[i-1]); else sum_right[i]=sum_right[i+k]+1ll*l-a[i-1]+min(a[i-1],l-a[i-1]); ll res=min(sum_left[n],sum_right[1]); for(int i=1;i<n;i++) res=min(res,sum_left[i]+sum_right[i+1]); return res; } #ifdef SKY int main() { freopen("A.inp","r",stdin); freopen("A.out","w",stdout); // ios::sync_with_stdio(0); // cin.tie(NULL); // cout.tie(NULL); int n,k,l; cin>>n>>k>>l; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; cout<<delivery(n,k,l,a); return 0; } #endif // SKY
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...