Submission #1057257

#TimeUsernameProblemLanguageResultExecution timeMemory
10572570npataJobs (BOI24_jobs)C++17
0 / 100
104 ms5204 KiB
#include<bits/stdc++.h>
using namespace std;

#define vec vector
#define int long long

int32_t main() {
	int N, S;
	cin >> N >> S;

	vec<int> X(N), P(N);
	for(int i = 0; i<N; i++) {
		cin >> X[i] >> P[i];
	}

	map<int, int> thrs{};

	int i = 0;
	while(i<N) {
		int s = i;
		while(++i < N && P[i] != 0) {};
		int e = i;
		int pref_sum_mx = 0;
		int pref_sum_mx_prev = 0;
		int pref_sum_mn = 0;
		int pref_sum = 0;
		for(int j = s; j<e; j++) {
			//cerr << X[i] << ' ';
			pref_sum += X[j];
			pref_sum_mx = max(pref_sum_mx, pref_sum);
			pref_sum_mn = min(pref_sum_mn, pref_sum);
			thrs[-pref_sum_mn] += (pref_sum_mx-pref_sum_mx_prev);
			pref_sum_mx_prev = pref_sum_mx;
		}
		//cerr << '\n';
	}


	int money = S;
	for(auto [t, g] : thrs) {
		if(money >= t) {
			money += g;
		}
		else {
			break;
		}
	}

	cout << money - S << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...