提出 #67981263


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void test() {
    int N; ll M;
    cin >> N >> M;
    
    ll A[N+1], B[N+1];
    for (int i = 1; i <= N; i++) cin >> A[i];
    for (int i = 1; i <= N; i++) cin >> B[i];
    
    sort(A+1, A+N+1);
    sort(B+1, B+N+1);
    ll sum_AB = accumulate(A+1, A+N+1, 0LL) + accumulate(B+1, B+N+1, 0LL);
    
    int l = 0, r = N+1;
    while (r-l > 1) {
        int mid = (l+r)>>1;
        bool pass = true;
        for (int i = 0; i < mid; i++)
            pass &= (A[N-i]+B[N-mid+i+1] >= M);
        if (pass) l = mid;
        else r = mid;
    }
    
    cout << sum_AB - M*l << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int T;
    cin >> T;
    while (T--) test();
}

提出情報

提出日時
問題 D - Match, Mod, Minimize 2
ユーザ omsincoconut
言語 C++ 20 (gcc 12.2)
得点 400
コード長 814 Byte
結果 AC
実行時間 76 ms
メモリ 8164 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 30
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3480 KiB
01_handmade_00.txt AC 71 ms 8152 KiB
01_handmade_01.txt AC 37 ms 8164 KiB
01_handmade_02.txt AC 42 ms 8096 KiB
01_handmade_03.txt AC 73 ms 8148 KiB
01_handmade_04.txt AC 1 ms 3480 KiB
01_handmade_05.txt AC 21 ms 3412 KiB
02_random_00.txt AC 75 ms 8096 KiB
02_random_01.txt AC 76 ms 8100 KiB
02_random_02.txt AC 75 ms 8092 KiB
02_random_03.txt AC 75 ms 8148 KiB
02_random_04.txt AC 47 ms 3392 KiB
02_random_05.txt AC 47 ms 3464 KiB
02_random_06.txt AC 48 ms 3416 KiB
02_random_07.txt AC 48 ms 3420 KiB
02_random_08.txt AC 47 ms 3464 KiB
02_random_09.txt AC 47 ms 3476 KiB
02_random_10.txt AC 60 ms 3616 KiB
02_random_11.txt AC 60 ms 3568 KiB
02_random_12.txt AC 60 ms 3616 KiB
02_random_13.txt AC 60 ms 3616 KiB
02_random_14.txt AC 59 ms 3756 KiB
02_random_15.txt AC 60 ms 3608 KiB
02_random_16.txt AC 54 ms 3468 KiB
02_random_17.txt AC 48 ms 3496 KiB
02_random_18.txt AC 48 ms 3556 KiB
02_random_19.txt AC 48 ms 3420 KiB
02_random_20.txt AC 48 ms 3492 KiB
02_random_21.txt AC 48 ms 3484 KiB
02_random_22.txt AC 48 ms 3484 KiB