QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#677242#9528. New Energy Vehicleucup-team3931#WA 1ms7972kbC++141.2kb2024-10-26 10:44:202024-10-26 10:44:20

Judging History

This is the latest submission verdict.

  • [2024-10-26 10:44:20]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7972kb
  • [2024-10-26 10:44:20]
  • Submitted

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 100100;

ll n, m, a[maxn], c[maxn];
pii b[maxn];
vector<ll> vc[maxn];

void solve() {
	scanf("%lld%lld", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		c[i] = a[i];
		vector<ll>().swap(vc[i]);
	}
	for (int i = 1; i <= m; ++i) {
		scanf("%lld%lld", &b[i].fst, &b[i].scd);
		vc[b[i].scd].pb(b[i].fst);
	}
	for (int i = 1; i <= n; ++i) {
		vc[i].pb(1e18);
		reverse(vc[i].begin(), vc[i].end());
	}
	set<pii> S;
	ll ans = 0, j = 1;
	for (int i = 1; i <= n; ++i) {
		S.emplace(vc[i].back(), i);
	}
	while (S.size()) {
		pii p = *S.begin();
		S.erase(S.begin());
		ans += a[p.scd];
		a[p.scd] = 0;
		while (j <= m) {
			a[b[j].scd] = c[b[j].scd];
			vc[b[j].scd].pop_back();
			S.emplace(vc[b[j].scd].back(), b[j].scd);
			++j;
		}
	}
	printf("%lld\n", ans);
}

int main() {
	int T = 1;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7316kb

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
Wrong Answer
time: 1ms
memory: 7972kb

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:

8
9
6
9
1999999998
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '8'