답안 #44433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44433 2018-04-02T07:10:56 Z ssnsarang2023 Candies (JOI18_candies) C++17
0 / 100
3 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, int> pli;

const int N = (int)2e5+5;
const ll oo = (ll)1e16;
int n, nxt[N], pre[N];
ll a[N];
priority_queue<pli> pq;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		nxt[i] = i + 1, pre[i] = i - 1;
		pq.push(pli(a[i], i));
	}
	ll ans = 0;
	for (int i = 1; i <= ((n + 1) >> 1); ++i) {
		for (; pq.top().first != a[pq.top().second]; pq.pop());
		int x = pq.top().second, l = pre[x], r = nxt[x];
		printf("%lld\n", ans += a[x]);
		pq.pop();
		pre[nxt[x] = nxt[r]] = x;
		nxt[pre[x] = pre[l]] = x;
		a[x] = l && r ? max(-oo, a[l] + a[r] - a[x]) : -oo;
		a[l] = a[r] = -oo;
		pq.push(pli(a[x], x));
	}
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
candies.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -