이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 500001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;
int n;
ll v[NMAX], a, b;
int main() {
//ifstream cin("niceset.in");
//ofstream cout("niceset.out");
int i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> a >> b;
a -= b;
v[i] = a;
v[i] += v[i - 1];
}
ll sol = 0;
priority_queue <ll> pq;
for(i = 1; i <= n; i++){
if(v[i] < 0){
sol += -v[i];
v[i] = 0;
}
if(v[i] > v[n]){
sol += (v[i] - v[n]);
v[i] = v[n];
}
pq.push(v[i]);
pq.push(v[i]);
sol += (v[n] - v[i]);
sol -= (v[n] - pq.top());
pq.pop();
}
cout << sol;
return 0;
}
# | 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... |