# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
216757 | 2020-03-28T03:26:17 Z | mohamedsobhi777 | Boxes with souvenirs (IOI15_boxes) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "boxes.h" using namespace std ; const int M_N = 1e5 + 7 ; long long delivery(int N, int K, int L, int p[]) { int ret = 0 ; int pivot = 0 ; sort(p , p + N) ; for(int i =0 ; i < N ; i++){ if(p[i] <=L /2 ){ pivot = i ; } } int cur = 0 , swp = 0 ; for(int i = 0 ; i <=pivot ; i++){ cur++; if(cur==k){ ret+=2*p[i] ; cur = 0 ; swp = i ; } } for(int i = 0 ; i <=swp ; i++)p[i] = 0; cur = 0 , swp = N ; for(int i = N-1 ; i>pivot ; i--){ cur++ ; if(cur==k){ ret+=2*(L - p[i]) ; cur = 0 ; swp = i ; } } for(int i = swp ; i <N ; i++)p[i] = 0 ; int road1 = 0 ; int road2 = 0 ; for(int i = 0 ; i < N;i++){ if(i<=pivot){ road1 = 2 * p[i] ; }else if(!road2 && p[i]){ road2 = 2*(L - p[i]) ; } } ret+=min(L , road1 + road2) ; return 1ll * ret; }