# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
216798 | 2020-03-28T04:50:22 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 solve1(int N , int K, int L , int p[]){ long long ret = 0 , pivot = -1 ; sort(p , p + N) ; for(int i =0 ; i < N ; i++){ if(p[i] <=L /2 ) pivot = i ; } long long cur = 0 , swp = -1 ; for(int i = 0 ; i <=pivot ; i++){ cur++; if(cur==K){ ret+=2ll*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+=2ll*(L - p[i]) ; cur = 0 ; swp = i ; } } for(int i = swp ; i <N ; i++)p[i] = 0 ; long long road1 = 0 , road2 = 0, road3 = 0; for(int i = 0 ; i < N;i++){ if(i<=pivot){ road1 = 2ll * p[i] ; }else if(!road2 && p[i]){ road2 = 2ll*(L - p[i]) ; } } return ret + road1 + road2 ; }