QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682336#9528. New Energy Vehicleucup-team2432#RE 0ms3532kbC++201.6kb2024-10-27 15:02:442024-10-27 15:02:45

Judging History

This is the latest submission verdict.

  • [2024-10-27 15:02:45]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3532kb
  • [2024-10-27 15:02:44]
  • Submitted

answer

#include <bits/stdc++.h>
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using db = double;
using i128 = __int128;
#define Emu Smile
using namespace std;

const ll inf = 1e18;

void yes() { cout << "Yes\n"; }
void no() { cout << "No\n"; }

void chmax(auto &a,auto b) { if (a < b) a = b; }
void chmin(auto &a,auto b) { if (a > b) a = b; }

void solve() {
	int n,m; cin >> n >> m;
	vector<ll> a(n);
	for (auto &x : a) {
		cin >> x;
	}
	vector eg(n, vector<ll>());
	vector<int> c(n), p(n), be(n);
	for (int i = 0, x; i < m; ++i) {
		cin >> c[i] >> x; x--;
		eg[x].emplace_back(i);
		be[i] = x;
	}
	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<>> q;
	vector<ll> remain(n);
	for (int i = 0; i < n; ++i) {
		eg[i].emplace_back(inf);
		remain[i] = a[i];
		q.emplace(eg[i][0], i);
	}
	ll ret = 0;
	for (int i = 0; i < m; ++i) {
		while (!q.empty()) {
			auto [pos, id] = q.top();
			ll mint = min(c[i] - ret, remain[id]);
			ret += mint, remain[id] -= mint;
			if (!remain[id]) { q.pop(); }
			if (ret == c[i]) break;
		}
		if (ret == c[i]) {
			int id = be[i];
			if (q.top().second == id) { q.pop(); }
			remain[id] = a[i]; p[id] ++;
			q.emplace(eg[i][p[id]], i);
		} else {
			break;
		}
	}
	for (auto x : remain) {
		ret += x;
	}
	cout << ret << '\n';
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);

	cout << fixed << setprecision(10);

//	init();

	int OuO = 1;
	cin >> OuO;
	for (int piastic = 0; piastic < OuO; ++piastic) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:


result: