제출 #1247791

#제출 시각아이디문제언어결과실행 시간메모리
1247791lukav나일강 (IOI24_nile)C++20
23 / 100
2095 ms5156 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vec vector

string to_string(pair<int, int> numbers) {
	return '(' + to_string(numbers.first) + ", " + to_string(numbers.second) + ')';
}
string to_string(vec<int> numbers) {
	string text = "{";
	for (auto i = numbers.begin(); i != numbers.end(); i++) {
		text += to_string(*i);
		if (next(i) != numbers.end()) {text += ", ";}
	} text += '}';
	return text;
}
string to_string(vec<ll> numbers) {
	string text = "{";
	for (auto i = numbers.begin(); i != numbers.end(); i++) {
		text += to_string(*i);
		if (next(i) != numbers.end()) {text += ", ";}
	} text += '}';
	return text;
}
string to_string(vec<pair<int, int>> numbers) {
	string text = "{";
	for (auto i = numbers.begin(); i != numbers.end(); i++) {
		text += to_string(*i);
		if (next(i) != numbers.end()) {text += ", ";}
	} text += '}';
	return text;
}
//bool comp(int a, int b) {return a > b;}

vec<ll> calculate_costs(vec<int> W, vec<int> A, vec<int> B, vec<int> E) {
	int n = W.size(), q = E.size();
	vec<int> Ecopy = E;
	sort(Ecopy.begin(), Ecopy.end());
	//cout << to_string(Ecopy) << endl << to_string(E);
	ll constant = 0;
	for (int i = 0; i < n; i++) {
		constant += B[i];
		A[i] -= B[i];
	}
	vec<pair<int, int>> artifacts;
	for (int i = 0; i < n; i++) {
		artifacts.push_back(make_pair(W[i], A[i]));
	}
	sort(artifacts.begin(), artifacts.end());

	//vec<pair<vec<pair<int, int>>     ,  vec<int>    >>  //vec of pairvec (artifacts, otherinfo)
	//cout << to_string(artifacts);
	//cout << constant << endl << to_string(A) << to_string(B);


	vec<ll> answers;
	//cout << to_string(artifacts) << endl;
	for (int i = 0; i < q; i++) {
		int D = E[i];
		ll answ = constant;

		int minimum = artifacts[0].second;
		int index = 0;
		for (int j = 1; j < n; j++) {
			if (abs(artifacts[j].first - artifacts[j - 1].first) > D) {
				if ((j - index) % 2 == 1) {answ += minimum;}
				minimum = artifacts[j].second;
				index = j;
			} else {
				if (artifacts[j].second < minimum && (j == n - 1 || abs(artifacts[j + 1].first - artifacts[j - 1].first)) <= D) {
					minimum = artifacts[j].second;
				}
			}
			if (j == n - 1) {if ((j - index) % 2 == 0) {answ += minimum;}}
		} answers.push_back(answ);//cout << answ << endl;
	}
	//cout << to_string(answers);
	return answers;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...