QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#510073#8034. Ban or Pick, What's the Trick333zhanWA 0ms4084kbC++201.1kb2024-08-08 20:58:332024-08-08 20:58:34

Judging History

This is the latest submission verdict.

  • [2024-08-08 20:58:34]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 4084kb
  • [2024-08-08 20:58:33]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

inline int read () {
    int w = 1, s = 0; char ch = getchar ();
    for (; ! isdigit (ch); ch = getchar ()) if (ch == '-') w = -1;
    for (; isdigit (ch); ch = getchar ()) s = (s << 1) + (s << 3) + (ch ^ 48);
    return s * w;
}

void solve () {
	int n = read (), k = read ();
    
    vector <int> a (n), b (n);
    for (int i = 0; i < n; i ++) {
        a[i] = read ();
    }
    for (int i = 0; i < n; i ++) {
        b[i] = read ();
    }

    sort (a.begin (), a.end ());
    sort (b.begin (), b.end ());

    vector <int> c (n);
    for (int i = 0; i < n; i ++) {
        c[i] = a[i] - b[i];
    }
    sort (c.begin (), c.end (), greater ());

    int ans = 0;
    for (int i = 0, j = 0; i < n && j < k; i ++, j ++) {
        if (c[i] < 0) {
            break;
        }
        ans += c[i];
    }

    printf ("%lld\n", ans);
} 

signed main () {
	// ios::sync_with_stdio (false);
    // cin.tie (nullptr);
    
	int T = 1; 
	// cin >> T;
	// T = read ();

	while (T --) {
		solve ();
	}
	
	return 0;
}

详细

Test #1:

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

input:

2 1
3 6
2 4

output:

2

result:

ok single line: '2'

Test #2:

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

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: 4064kb

input:

4 2
4 6 7 9
2 5 8 10

output:

3

result:

ok single line: '3'

Test #4:

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

input:

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

output:

45

result:

wrong answer 1st lines differ - expected: '41', found: '45'