#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
int n;
cin >> n;
set<pair<ll, int>>s1;
set<pair<int, ll>>s2;
for(int i = 1; i <= n; i++){
ll x;
cin >> x;
s1.emplace(-x, i);
s2.emplace(i, -x);
}
s1.emplace(INF, 0);
s1.emplace(INF, n + 1);
s2.emplace(0, INF);
s2.emplace(n + 1, INF);
ll ans = 0;
for(int _ = 0; _ < (n >> 1); _++){
auto [x, i] = *s1.begin();
auto it = s2.lower_bound(make_pair(i, x));
auto a = *--it;
s1.erase(make_pair(a.second, a.first));
s2.erase(it++);
auto b = *it;
s1.erase(make_pair(b.second, b.first));
s2.erase(it++);
auto c = *it;
s1.erase(make_pair(c.second, c.first));
s2.erase(it);
s1.emplace(a.second + c.second - b.second, b.first);
s2.emplace(b.first, a.second + c.second - b.second);
}
}
컴파일 시 표준 에러 (stderr) 메시지
candies.cpp: In function 'int main()':
candies.cpp:9:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |