Submission #1265092

#TimeUsernameProblemLanguageResultExecution timeMemory
1265092Bui_Quoc_CuongCandies (JOI18_candies)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h> #define int long long template <class A, class B> bool maximize (A &a, const B b){ if (a < b) { a = b; return true; } return false; } template <class A, class B> bool minimize (A &a, const B b) { if (a > b) { a = b; return true; } return false; } #define FOR(i, a, b) for(int i = (a); i <= (int)(b); i++) #define FORD(i, a, b) for(int i = (a); i >= (int)(b); i--) #define fi first #define se second #define pb push_back #define ALL(A) A.begin(), A.end() #define BIT(mask,i) ((mask>>(i))&1) #define ll long long using namespace std; const int maxN = 2e5 + 5; int n; int a[maxN], L[maxN], R[maxN], dd[maxN]; void init(void) { cin >> n; FOR(i, 1, n) cin >> a[i]; } void process(void) { a[0] = a[n + 1] = - 2e9; priority_queue <pair <int, int>, vector <pair <int, int>>> PQ; FOR(i, 1, n) { L[i] = i - 1; R[i] = i + 1; PQ.push({a[i], i}); } long long ans = 0; FOR(id, 1, (n + 1) / 2) { while (!PQ.empty() && dd[PQ.top().second]) { PQ.pop(); } int i = PQ.top().second; PQ.pop(); dd[L[i]] = dd[R[i]] = 1; ans+= a[i]; a[i] = a[L[i]] + a[R[i]] - a[i]; PQ.push({a[i], i}); L[i] = L[L[i]]; R[L[i]] = i; R[i] = R[R[i]]; L[R[i]] = i; cout << ans << "\n"; } } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define koa "candies" if (fopen(koa".inp", "r")) { freopen(koa".inp", "r", stdin); freopen(koa".out", "w", stdout); } init(); process(); return 0; }

Compilation message (stderr)

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