Submission #251874

# Submission time Handle Problem Language Result Execution time Memory
251874 2020-07-22T14:31:30 Z lyc Candies (JOI18_candies) C++14
0 / 100
2 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
using ii=pair<long long,int>;

const int mxN = 2e5+5;

int N;
multiset<ii> ms;
map<int,long long> mp;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N;
    FOR(i,1,N){
		int A; cin >> A;
		ms.insert(ii(A,i));
		mp[i] = A;
	}
	
	long long ans = 0;
	FOR(_i,1,(N+1)/2){
		auto i = prev(ms.end());
		ans += i->first;
		auto y = mp.find(i->second);
		ii nw = ii(-i->first, i->second);
		
		bool ins = 1;
		if (y != mp.begin()) {
			auto x = prev(y);
			ms.erase(ii(x->second,x->first));
			nw.first += x->second;
			mp.erase(x);
		} else ins = 0;
		if (next(y) != mp.end()) {
			auto z = next(y);
			ms.erase(ii(z->second,z->first));
			nw.first += z->second;
			mp.erase(z);
		} else ins = 0;
		
		ms.erase(i);
		mp.erase(y);
		if (ins) ms.insert(nw);
		mp[nw.second] = nw.first;
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -