제출 #496176

#제출 시각아이디문제언어결과실행 시간메모리
496176kevin선물상자 (IOI15_boxes)C++17
70 / 100
1097 ms524292 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define nl cout<<"\n" #define ca(v) for(auto i:v) cout<<i<<" "; ll delivery(int N, int K, int L, int* a){ vector<ll> ar; for(int i=0; i<N; i++) ar.push_back((ll)a[i]); sort(ar.begin(), ar.end()); vector<vector<ll>> cost(N, vector<ll>(2, 0)); for(int i=0; i<N; i++){ if(i<K) { cost[i][0] = ar[i] + min(ar[i], L - ar[i]); cost[N-1-i][1] = (L - ar[N-1-i]) + min(ar[N-1-i], L - ar[N-1-i]); } else { cost[i][0] = ar[i] + min(ar[i], L - ar[i]) + cost[i-K][0]; cost[N-1-i][1] = (L - ar[N-1-i]) + min(ar[N-1-i], L - ar[N-1-i]) + cost[N-1-i+K][1]; } } ll ans = cost[0][1]; ans = min(ans, cost[N-1][0]); for(int i=0; i<N-1; i++){ ans = min(ans, cost[i][0] + cost[i+1][1]); //- max(min(ar[i], L - ar[i]), min(ar[i+1], L - ar[i+1]))); } return ans; } // int main() // { // ios_base::sync_with_stdio(0); cin.tie(0); // if (fopen("input.in", "r")) freopen("input.in", "r", stdin); // int N, K, L; // cin>>N>>K>>L; // vector<int> ar(N); // for(int i=0; i<N; i++) cin>>ar[i]; // cout<<delivery(N, K, L, ar); // }
#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...