Submission #1263375

#TimeUsernameProblemLanguageResultExecution timeMemory
1263375SmuggingSpunCandies (JOI18_candies)C++20
100 / 100
322 ms26988 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	int n;
	cin >> n;
	multiset<pair<ll, int>>s1;
	multiset<pair<int, ll>>s2;
	for(int i = 1; i <= n; i++){
		ll x;
		cin >> x;
		s1.emplace(-x, i);
		s2.emplace(i, -x);
	}
	s1.emplace(INF, 0);
	s1.emplace(INF, n + 1);
	s2.emplace(0, INF);
	s2.emplace(n + 1, INF);
	ll ans = 0;
	for(int _ = 0; _ < ((n + 1) >> 1); _++){
		auto [x, i] = *s1.begin();
		cout << (ans -= x) << "\n";
		auto it = s2.find(make_pair(i, x));
		auto a = *--it;
		s1.erase(s1.find(make_pair(a.second, a.first)));
		s2.erase(it++);
		auto b = *it;
		s1.erase(s1.find(make_pair(b.second, b.first)));
		s2.erase(it++);
		auto c = *it;
		s1.erase(s1.find(make_pair(c.second, c.first)));
		s2.erase(it);
		s1.emplace(a.second + c.second - b.second, b.first);
		s2.emplace(b.first, a.second + c.second - b.second);
	}
}

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:9:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...