Submission #912358

# Submission time Handle Problem Language Result Execution time Memory
912358 2024-01-19T10:18:06 Z vjudge1 Potatoes and fertilizers (LMIO19_bulves) C++17
24 / 100
89 ms 5408 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define ent "\n"

const int inf = (int)1e9 + 100;
const int maxn = 5e5 + 100;
const ll INF = (ll)1e18;
const int MOD = 1e9 + 7;
const int maxl = 62500;
const ll P = 31, T = 0;

int n;
int a[maxn];
int b[maxn];

void test(){
	cin >> n;
	vector<int> v;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		if(a[i] > b[i]){
			v.push_back(i);
		}
	}
	ll ans = 0;
	for(int i = n; i > 0; i--){
		if(a[i] > b[i]) continue;
		while(a[i] < b[i]){
			int cnt = min(b[i] - a[i], a[v.back()] - b[v.back()]);
			a[i] += cnt; a[v.back()] -= cnt;
			ans += 1ll * cnt * abs(v.back() - i);
			if(a[v.back()] == b[v.back()]) v.pop_back();
		}
	}
	cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
    // #endif
    int t = 1;
    if(T) cin >> t;
    while(t--) test();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2408 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 6 ms 2908 KB Output is correct
5 Correct 11 ms 3048 KB Output is correct
6 Correct 33 ms 3532 KB Output is correct
7 Correct 89 ms 5388 KB Output is correct
8 Correct 52 ms 5324 KB Output is correct
9 Correct 66 ms 5324 KB Output is correct
10 Correct 40 ms 5260 KB Output is correct
11 Correct 39 ms 5408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2408 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 6 ms 2908 KB Output is correct
5 Correct 11 ms 3048 KB Output is correct
6 Correct 33 ms 3532 KB Output is correct
7 Correct 89 ms 5388 KB Output is correct
8 Correct 52 ms 5324 KB Output is correct
9 Correct 66 ms 5324 KB Output is correct
10 Correct 40 ms 5260 KB Output is correct
11 Correct 39 ms 5408 KB Output is correct
12 Incorrect 18 ms 3040 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2408 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2408 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2408 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -