이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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* ar){
sort(ar, ar+N);
vector<vector<ll>> cost(N, vector<ll>(2, 0));
vector<ll> cost0(N, 0);
vector<ll> cost1(N, 0);
for(int i=0; i<N; i++){
if(i<K) {
cost0[i] = (ll)ar[i] + min(ar[i], L - ar[i]);
cost1[N-1-i] = (ll)(L - ar[N-1-i]) + min(ar[N-1-i], L - ar[N-1-i]);
}
else {
cost0[i] = (ll)ar[i] + min(ar[i], L - ar[i]) + cost0[i-K];
cost1[N-1-i] = (ll)(L - ar[N-1-i]) + min(ar[N-1-i], L - ar[N-1-i]) + cost1[N-1-i+K];
}
}
ll ans = cost1[0];
ans = min(ans, cost0[N-1]);
for(int i=0; i<N-1; i++){
ans = min(ans, cost0[i] + cost1[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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |