Submission #912364

# Submission time Handle Problem Language Result Execution time Memory
912364 2024-01-19T10:23:05 Z vjudge1 Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
2 ms 344 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];
int mx[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;
			mx[i] = max(mx[i], abs(v.back() - i));
			ans += 1ll * cnt * abs(v.back() - i);
			if(a[v.back()] == b[v.back()]) v.pop_back();
		}
	}
	if(v.size()){
		int add = 0;
		for(int i = 1; i <= n; i++){
			add = min(add, abs(i - v.back()) - mx[i]);
		}
	}
	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();
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:53:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |      freopen("input.txt", "r", stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:54:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |      freopen("output.txt", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -