제출 #1075902

#제출 시각아이디문제언어결과실행 시간메모리
1075902TB_선물상자 (IOI15_boxes)C++17
20 / 100
1 ms432 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fo(i, n) for(ll i = 0; i<(n); i++) #define F first #define S second #define deb(x) cout << #x << " = " << (x) << endl #define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl long long delivery(int N, int K, int L, int p[]) { priority_queue<ll> pq; fo(i, N){ pq.push(p[i]); } ll ans = 1e18; ll res = 0; while(!pq.empty()){ ll pos = 0; fo(i, K){ if(pq.empty()) break; // deb2(res, pq.size()); ll next = pq.top(); pq.pop(); res+=min((next-pos+L)%L, (pos-next+L)%L); // deb2((next-pos+L)%L, (pos-next+L)%L); pos = next; } ll next = 0; res+=min((next-pos+L)%L, (pos-next+L)%L); } ans = res; fo(i, N){ pq.push(-p[i]); } while(!pq.empty()){ ll pos = 0; fo(i, K){ if(pq.empty()) break; ll next = -pq.top(); pq.pop(); res+=min((next-pos+L)%L, (pos-next+L)%L); } ll next = 0; res+=min((next-pos+L)%L, (pos-next+L)%L); } ans = min(res, ans); return ans; }
#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...