- using namespace std;
- #include <bits/stdc++.h>
- void solve() {
- int n;
- cin >> n;
- vector<int> a(n), b(n);
- for (int i = 0; i < n; ++i)
- cin >> a[i];
- for (int i = 0; i < n; ++i)
- cin >> b[i];
- sort(a.begin(), a.end());
- sort(b.rbegin(), b.rend());
- int score = 0;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) if (a[j] != -1) {
- if (a[j] > b[i]) {
- score += 2;
- a[j] = b[i] = -1;
- break;
- }
- }
- }
- for (int i = 0; i < n; ++i) if (b[i] != -1) {
- for (int j = 0; j < n; ++j) if (a[j] != -1) {
- if (a[j] == b[i]) {
- score += 1;
- a[j] = b[i] = -1;
- break;
- }
- }
- }
- printf("%d\n", score);
- }
- int main() {
- int tc; cin >> tc;
- for (int i = 0; i < tc; ++i) {
- printf("Case %d: ", i + 1);
- solve();
- }
- return 0;
- }
Thursday, 27 July 2017
Lightoj 1198 - Karate Competition
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
You Can solve it using DP..
ReplyDeleteI know. I found it easier to understand. :)
Deleteyour solution is not correct for all possible input set.
ReplyDeleteCan you mention such a case? :)
Delete