| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1286491 | CrabCNH | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 163 ms | 16416 KiB |
#include <bits/stdc++.h>
#define task "htgdtctn"
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define szf sizeof
#define sz(s) (int)((s).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
template <class T> void minimize (T &t, T f) {if (t > f) t = f;}
template <class T> void maximize (T &t, T f) {if (t < f) t = f;}
const int maxN = 5e5 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;
// mt19937_64 rd (chrono :: steady_clock :: now ().time_since_epoch ().count ());
// int Rand (int l, int r) {return uniform_int_distribution <int> (l, r) (rd);}
pii a[maxN];
int b[maxN];
inline void Solve () {
int n;
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i].fi >> a[i].se;
b[i] = a[i].fi - a[i].se + b[i - 1];
}
int res = 0;
priority_queue <int> pq;
for (int i = 1; i < n; i ++) {
if (b[i] < 0) {
res += -b[i];
b[i] = 0;
}
res += b[i];
pq.push (b[i]);
pq.push (b[i]);
pq.pop ();
}
while (!pq.empty ()) {
int val = pq.top ();
pq.pop ();
res -= min (val, b[n]);
}
cout << res;
return;
}
signed main () {
cin.tie (nullptr) -> sync_with_stdio (false);
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t --) {
Solve ();
}
return 0;
}
// wake me up when September ends
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
