답안 #251845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251845 2020-07-22T11:07:37 Z lyc Candies (JOI18_candies) C++14
0 / 100
3 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 = 0;
		if (y != mp.begin()) {
			ins = 1;
			auto x = prev(y);
			ms.erase(ii(x->second,x->first));
			nw.first += x->second;
			mp.erase(x);
		}
		if (next(y) != mp.end()) {
			ins = 1;
			auto z = next(y);
			ms.erase(ii(z->second,z->first));
			nw.first += z->second;
			mp.erase(z);
		}
		
		ms.erase(i);
		mp.erase(y);
		if (ins) {
			ms.insert(nw);
			mp[nw.second] = nw.first;
		}
		cout << ans << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -