QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669691#8034. Ban or Pick, What's the TrickPoorGhostWA 1ms5656kbC++201.6kb2024-10-23 19:24:012024-10-23 19:24:01

Judging History

This is the latest submission verdict.

  • [2024-10-23 19:24:01]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5656kb
  • [2024-10-23 19:24:01]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;
int n, k;
int a[N], b[N], c[N];
bool st[N];
void solve()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
	}
	sort(a + 1, a + 1 + n, [&](int x, int y) {return x > y;});
	sort(b + 1, b + 1 + n, [&](int x, int y) {return x > y;});
	for (int i = 1; i <= n; i++)
	{
		c[i] = a[i] - b[i];
	}
	sort(c + 1, c + 1 + n, [&](int x, int y) {return x > y;});
	map<int, int>mp;
	for (int i = 1; i <= k; i++)
		mp[c[i]]++;
	for (int i = 1; i <= n; i++)
	{
		int cha = a[i] - b[i];
		if (mp.count(cha))
		{
			st[i] = true;
			mp[cha]--;
			if (mp[cha] == 0) mp.erase(cha);
		}
	}
	int L = 1, R = 1;
	vector<int>aa, bb;
	int op = 0;
	while (L <= n || R <= n)
	{
		if (!op)
		{
			if (!st[R] && R <= n)
			{
				if (a[L] < b[R])
					R++;
				else aa.push_back(a[L++]);
			}
			else
			{
				if (L <= n && a[L] >= b[R])
					aa.push_back(a[L++]);
				else R++;
			}
		}
		else
		{
			if (!st[L] && L <= n)
			{
				if (a[L] > b[R])
					L++;
				else bb.push_back(b[R++]);
			}
			else
			{
				if (R <= n && a[L] <= b[R])
					bb.push_back(b[R++]);
				else L++;
			}
		}
		op ^= 1;
	}
	int ans = 0;
	for (int i = 0; i < min((int)(aa.size()), k); i++)
	{
		ans += aa[i];
	}
	for (int i = 0; i < min((int)(bb.size()), k); i++)
	{
		ans -= bb[i];
	}
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int test = 1;
	// cin >> test;
	for (int i = 1; i <= test; i++)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4 1
1 3 5 7
2 4 6 8

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

4 2
4 6 7 9
2 5 8 10

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

10 5
42 13 60 42 100 82 22 98 14 55
100 41 89 24 65 38 69 26 37 16

output:

41

result:

ok single line: '41'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5656kb

input:

9 10
4 32 566 885 439 479 332 95 432
409 140 704 26 558 781 457 356 404

output:

58

result:

ok single line: '58'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

20 8
249 888 548 338 840 890 519 416 852 817 28 694 271 947 239 11 654 914 765 939
483 148 403 552 250 635 287 644 364 822 621 151 31 422 683 959 867 266 837 395

output:

1241

result:

wrong answer 1st lines differ - expected: '1201', found: '1241'