Submission #418203

# Submission time Handle Problem Language Result Execution time Memory
418203 2021-06-05T08:13:59 Z Kevin_Zhang_TW Arranging Tickets (JOI17_arranging_tickets) C++17
0 / 100
5 ms 7244 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 300010;
const ll inf = 1ll << 55;

int n, m;

vector<pair<int,ll>> rc[MAX_N];

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	vector<tuple<int,int,int>> req(m);
	for (auto &[l, r, c] : req) {
		cin >> l >> r >> c;
		if (l > r) swap(l, r);
		//assert(c == 1);
	}

	vector<ll> sum(n + 10);

	for (auto [l, r, c] : req)
		sum[l] += c, sum[r] -= c;

	for (auto [l, r, c] : req) rc[l].pb(r, c);

	auto cal = [&](ll mx) {
		// first is right end, second is count
		priority_queue<pair<int,ll>> pq;
		vector<ll> pfsum(sum);

		ll use = 0;
		for (int i = 1;i <= n;++i) {
			for (auto [r, c] : rc[i]) 
				pq.emplace(r, c);

			pfsum[i] += pfsum[i-1];

			while (pfsum[i] > mx) {
				assert(pq.size());
				auto [r, c] = pq.top(); pq.pop();
				ll req = min(c, (pfsum[i] - mx + 1) / 2);
				use += req;
				pfsum[i] -= req * 2;
				pfsum[r] += req * 2;
				if (req < c) pq.emplace(r, c - req);
			}
		}

		return mx + use;
	};

	ll res = inf;

	for (int i : {0, 1}) {
		ll l = 0, r = inf, mid;
		while (l < r) {
			mid = l + r >> 1;
			ll x = (mid*2) + i, y = x + 2;
			if (cal(x) <= cal(y))
				r = mid;
			else
				l = mid+1;
		}
		chmin(res, cal(l));
	}

//	for (int i = 0;i <= m;++i) {
//		chmin(res, cal(i));
//	}

	cout << res << '\n';
	
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7244 KB Output isn't correct
2 Halted 0 ms 0 KB -