Submission #489240

#TimeUsernameProblemLanguageResultExecution timeMemory
489240ssense선물상자 (IOI15_boxes)C++14
10 / 100
3 ms324 KiB
#include <bits/stdc++.h>
#include "boxes.h"
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long  ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define nax 200005
#define pb push_back
#define sc second
#define fr first
//#define int unsigned long long
//#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl

 
long long delivery(int n, int k, int l, int a[])
{
	int now = 0;
	int stock = k;
	int ans = 0;
	while(true)
	{
		if(stock == 0)
		{
			ans+=min(now, l-now);
			now = 0;
			stock = k;
		}
		int dist = 2*MX, nod = -1, idx = -1;
		for(int i = 0; i < n; i++)
		{
			if(a[i] != -1)
			{
				if(min(max(now, a[i])-min(now, a[i]), l-max(now, a[i])+min(now, a[i])) < dist)
				{
					nod = a[i];
					idx = i;
					dist = min(max(now, a[i])-min(now, a[i]), l-max(now, a[i])+min(now, a[i]));
					
				}
			}
		}
		if(nod == -1)
		{
			ans+=min(now, l-now);
			break;
		}
		a[idx] = -1;
		ans+=dist;
		stock--;
		if(max(now, nod)-min(now, nod) >= l-max(now, nod)+min(now, nod))
		{
			stock = k;
		}
		now = nod;
	}
	return ans;
}
/*
int main()
{
	int n, k, l;
	cin >> n >> k >> l;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	cout << delivery(n, k, l, a) << endl;
}
 */
/*
3 2 8
1 2 5
 */
#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...