이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 5e5 + 5, mod = 1e9 + 7; // !
int t, d[N];
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n;
cin >> n;
// ans = jami(ai[i] - a[i]) = jami (d'[i] - d[i]);
priority_queue<int, vector<int>, less<int> > q;
int ans = 0;
for(int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
// a' - b >= 0 yvelastvis => d'[i + 1] >= d'[i]
d[i] = d[i - 1] + a - b;
if(d[i] < 0) ans += -d[i];
q.push(max(0ll, d[i]));
q.push(max(0ll, d[i]));
ans += q.top() - (max(0ll, d[i]));
q.pop();
}
q.push(d[n]);
int k = 1;
while(q.top() != d[n]) {
int x = q.top();
q.pop();
ans += k * (x - q.top());
++k;
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
bulves.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |