답안 #47909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47909 2018-05-08T14:53:04 Z Just_Solve_The_Problem Candies (JOI18_candies) C++11
0 / 100
3 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define ll long long

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int n;
priority_queue < pii > q;
int a[N], prv[N], nxt[N];

main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    q.emplace(mk(a[i], i));
    if (i > 1)
      prv[i] = i - 1;
    if (i < n)
      nxt[i] = i + 1;
  }
  ll ans = 0;
  for (int j = 1; j <= (n + 1) / 2; j++) {
    while (q.top().fr != a[q.top().sc]) q.pop();
    int i = q.top().sc;
    ans += q.top().fr;
    printf("%lld\n", ans);
    int l = prv[i];
    int r = nxt[i];
    nxt[i] = nxt[r];
    prv[i] = prv[l];
    nxt[prv[l]] = i;
    prv[nxt[r]] = i;
    if (l && r) {
      a[i] = max(-a[i] + a[l] + a[r], -inf);
    } else {
      a[i] = -inf;
    }
    a[l] = a[r] = -inf;
    q.emplace(mk(a[i], i));
  }
}

Compilation message

candies.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
candies.cpp: In function 'int main()':
candies.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
candies.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &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 -