Submission #1000718


Source Code Expand

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;

int a[maxn], b[maxn];
int N;
ll Min = 0;

bool check(int pos_a);

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) { scanf("%d", &a[i]); };
    for (int i = 0; i < N; ++i) { scanf("%d", &b[i]); };
    sort(a, a + N); sort(b, b + N);

    for (int i = 0; i < N; ++i) { Min += (ll)abs(a[i] - b[i]); }
    int low = 0, high = N - 1, mid;\
    while (low <= high) {
        mid = (low + high) >> 1;
        if (check(mid)) {
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
    printf("%d\n", low);
    return 0;
}

bool check(int pos_a) {
    int pos_b = 0;
    ll Min_t = 0;
    for (int i = pos_a; i < N; ++i, ++pos_b) { Min_t += (ll)abs(a[i] - b[pos_b]); }
    for (int i = pos_b, j = 0; i < N; ++i, ++j) { Min_t += (ll)abs(a[j] - b[i]); }
    if (Min_t == Min) { return true; }
    return false;
}

Submission Info

Submission Time
Task A - 1D Matching
User stop
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1070 Byte
Status WA
Exec Time 41 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:20:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
./Main.cpp:21:53: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < N; ++i) { scanf("%d", &a[i]); };
                                                     ^
./Main.cpp:22:53: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < N; ++i) { scanf("%d", &b[i]); };
                                                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 3
WA × 11
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt WA 25 ms 768 KB
001.txt WA 11 ms 384 KB
002.txt WA 14 ms 512 KB
003.txt WA 15 ms 512 KB
004.txt WA 37 ms 896 KB
005.txt WA 41 ms 1024 KB
006.txt WA 41 ms 1024 KB
007.txt WA 41 ms 1024 KB
008.txt WA 41 ms 1024 KB
009.txt WA 41 ms 1024 KB
010.txt WA 41 ms 1024 KB
011.txt AC 41 ms 1024 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 3 ms 256 KB