# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
158443 | davitmarg | 선물상자 (IOI15_boxes) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000000ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
int n;
LL k, m;
deque<int> pos;
LL ans;
LL delivery(int N, int K, int L, vector<int> P)
{
n = N;
k = K;
m = L;
for (int i = 0; i < N; i++)
if (P[i])
pos.PB(P[i]);
while (!pos.empty())
{
if (pos.size() >= 2 * k)
{
if (pos[k - 1] < (m - pos[pos.size() - k]))
{
ans += 2ll * pos[k - 1];
for (int i = 0; i < k; i++)
pos.pop_front();
}
else
{
ans += 2ll * (m - pos[pos.size() - k]);
for (int i = 0; i < k; i++)
pos.pop_back();
}
}
else
{
LL add1 = 0, add2 = 0;
add1 += min(2ll * pos[k - 1], m);
if (k < pos.size())
add1 += min(2ll * (m - pos[k]), m);
add2 += min(2ll * (m - pos[pos.size() - k]), m);
if (pos.size() - k - 1 >= 0)
add2 += min(2ll * pos[pos.size() - k - 1], m);
//cout << add1 << " : " << add2 << endl;
ans += min(add1, add2);
break;
}
}
return ans;
}
#ifdef death
int main()
{
int N, K, L;
vector<int> pos;
cin >> N >> K >> L;
for (int i = 0; i < N; i++)
{
pos.PB(0);
cin >> pos.back();
}
cout << delivery(N, K, L, pos) << endl;
return 0;
}
#endif
/*
3 2 8
1 2 5
*/