Submission #1115271

# Submission time Handle Problem Language Result Execution time Memory
1115271 2024-11-20T09:43:22 Z staszic_ojuz Stove (JOI18_stove) C++17
0 / 100
1 ms 2384 KB
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 500003;

int n;

pair<ll, ll> val[MAXN];

ll pref_b[MAXN];
ll max_pref_b[MAXN];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;

	for (int i = 1; n >= i; i++) {
		cin >> val[i].first >> val[i].second;
	}
	
	sort(val + 1, val + n + 1);
	
	for (int i = 1; n >= i; i++) {
		pref_b[i] = pref_b[i - 1] + val[i].second;
	}
	
	for (int i = 1; n >= i; i++) {
		max_pref_b[i] = max(max_pref_b[i - 1], val[i].first - pref_b[i - 1]);
	}
	
	ll wynik= 0;
	
	for (int i = 1; n >= i; i++) {
		wynik = max(wynik, pref_b[i] - val[i].first + max_pref_b[i]);
	}
	
	cout << wynik;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -