제출 #897633

#제출 시각아이디문제언어결과실행 시간메모리
897633oblantisBoxes with souvenirs (IOI15_boxes)C++17
20 / 100
1 ms348 KiB
#include "boxes.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e18 + 10000;
const int mod = 1e9+7;
const int maxn = 1e5 + 12;
long long delivery(int n, int k, int l, int p[]) {
	deque<int> ls, mr;
	for(int i = 0; i < n; i++){
		if(p[i] <= l / 2)ls.pb(p[i]);
		else mr.pb(p[i]);
	}
	ll ret = 0;
	while(int(ls.size()) >= k){
		int x = ls.back();
		for(int i = 0; i < k; i++){
			ls.pop_back();
		}
		ret += x * 2;
	}
	while(int(mr.size()) >= k){
		int x = mr.front();
		for(int i = 0; i < k; i++){
			mr.pop_front();
		}
		ret += (l - x) * 2;	
	}
	if(mr.empty() && ls.empty())return ret;
	else if(mr.empty() && !ls.empty())ret += ls.back() * 2;
	else if(!mr.empty() && ls.empty())ret += (l - mr.front()) * 2;
	else if(int(mr.size() + ls.size()) > k)ret += ls.back() * 2 + (l - mr.front()) * 2;
	else ret += min(l, ls.back() * 2 + (l - mr.front()) * 2);
	return ret;
}
#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...