| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1294768 | doowey | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 132 ms | 4668 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
fastIO;
int n;
cin >> n;
ll a, b;
priority_queue<ll> que;
vector<ll> P;
ll p = 0;
ll low = 0;
ll ans = 0;
for(int i = 1; i <= n; i ++ ){
cin >> a >> b;
p += a - b;
ll d = max(p,0ll);
ans += d - p;
if(i < n){
que.push(d);
que.push(d);
ans += que.top() - d;
que.pop();
}
}
ll xx = (ll)1e12;
int coeff = 0;
while(!que.empty() && que.top() > p){
ans += (xx - que.top()) * coeff;
xx = que.top();
que.pop();
coeff ++ ;
}
ans += (xx - p) * coeff;
cout << ans << "\n";
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... | ||||
