#include <iostream> //cin, cout
// #include <fstream>
// std::ifstream cin ("tallbarn.in");
// std::ofstream cout ("tallbarn.out");
// includes
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>
#include <bitset>
#include <complex>
//usings
using namespace std;
using namespace __gnu_pbds;
// misc
#define ll long long
#define ld long double
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template<typename T, typename U> bool emin(T &a, const U &b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool emax(T &a, const U &b){ return b > a ? a = b, true : false; }
typedef uint64_t hash_t;
// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz resize
#define all(x) x.begin(), x.end()
#define vc vector<char>
#define vvc vector<vc>
// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second
// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// maps
#define mii map<int, int>
#define mll map<ll, ll>
// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRE(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define FE(x, y) F(x, y + 1)
#define A(x, y) for(auto &x : y)
int main(){
int n; cin >> n;
vl a, b;
int suma = 0, sumb = 0;
F(i, n) {
int x; cin >> x; a.pb(x); suma += x;
cin >> x; b.pb(x); sumb += x;
}
ll cur = 0; ll an = 0;
priority_queue<ll> q;
F(i, n) {
cur += a[i] - b[i];
ll x = cur;
if(x < 0) an -= x, x = 0;
an += x;
q.push(x);
q.push(x);
q.pop();
}
while(!q.empty()) {
an -= min(q.top(), cur);
q.pop();
}
cout << an;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
2096 KB |
Output is correct |
5 |
Correct |
38 ms |
4040 KB |
Output is correct |
6 |
Correct |
137 ms |
10672 KB |
Output is correct |
7 |
Correct |
227 ms |
21016 KB |
Output is correct |
8 |
Correct |
216 ms |
19188 KB |
Output is correct |
9 |
Correct |
191 ms |
18404 KB |
Output is correct |
10 |
Correct |
143 ms |
16236 KB |
Output is correct |
11 |
Correct |
142 ms |
16296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
17 ms |
2096 KB |
Output is correct |
5 |
Correct |
38 ms |
4040 KB |
Output is correct |
6 |
Correct |
137 ms |
10672 KB |
Output is correct |
7 |
Correct |
227 ms |
21016 KB |
Output is correct |
8 |
Correct |
216 ms |
19188 KB |
Output is correct |
9 |
Correct |
191 ms |
18404 KB |
Output is correct |
10 |
Correct |
143 ms |
16236 KB |
Output is correct |
11 |
Correct |
142 ms |
16296 KB |
Output is correct |
12 |
Correct |
70 ms |
5564 KB |
Output is correct |
13 |
Correct |
159 ms |
15208 KB |
Output is correct |
14 |
Correct |
221 ms |
21156 KB |
Output is correct |
15 |
Correct |
218 ms |
19108 KB |
Output is correct |
16 |
Correct |
239 ms |
18556 KB |
Output is correct |
17 |
Correct |
135 ms |
16248 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
17 ms |
2096 KB |
Output is correct |
12 |
Correct |
38 ms |
4040 KB |
Output is correct |
13 |
Correct |
137 ms |
10672 KB |
Output is correct |
14 |
Correct |
227 ms |
21016 KB |
Output is correct |
15 |
Correct |
216 ms |
19188 KB |
Output is correct |
16 |
Correct |
191 ms |
18404 KB |
Output is correct |
17 |
Correct |
143 ms |
16236 KB |
Output is correct |
18 |
Correct |
142 ms |
16296 KB |
Output is correct |
19 |
Correct |
70 ms |
5564 KB |
Output is correct |
20 |
Correct |
159 ms |
15208 KB |
Output is correct |
21 |
Correct |
221 ms |
21156 KB |
Output is correct |
22 |
Correct |
218 ms |
19108 KB |
Output is correct |
23 |
Correct |
239 ms |
18556 KB |
Output is correct |
24 |
Correct |
135 ms |
16248 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
66 ms |
5508 KB |
Output is correct |
34 |
Correct |
193 ms |
15268 KB |
Output is correct |
35 |
Correct |
275 ms |
21156 KB |
Output is correct |
36 |
Correct |
235 ms |
18600 KB |
Output is correct |
37 |
Correct |
217 ms |
19104 KB |
Output is correct |
38 |
Correct |
270 ms |
21152 KB |
Output is correct |
39 |
Correct |
161 ms |
17320 KB |
Output is correct |
40 |
Correct |
173 ms |
16492 KB |
Output is correct |
41 |
Correct |
141 ms |
16324 KB |
Output is correct |
42 |
Correct |
136 ms |
16180 KB |
Output is correct |
43 |
Correct |
135 ms |
16280 KB |
Output is correct |
44 |
Correct |
138 ms |
16280 KB |
Output is correct |
45 |
Correct |
264 ms |
20924 KB |
Output is correct |
46 |
Correct |
170 ms |
16460 KB |
Output is correct |
47 |
Correct |
156 ms |
15300 KB |
Output is correct |