Submission #67964684


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N=3e5+10;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
map<int,int> mp;
int n,m,k;
int a[N],b[N];
void slove(){
    cin>>n>>m;
    int ans=0;
    int sum=0;
    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);
    int l=1,r=n;
    for(int i=1;i<=n;i++){
        int x=(a[i]+b[l])%m;
        int y=(a[i]+b[r])%m;
        if(x<y){
            ans+=x;
            l++;
        }
        else{
            ans+=y;
            r--;
        }
    }
    cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--){
        slove();
    }
}

Submission Info

Submission Time
Task D - Match, Mod, Minimize 2
User Maikan
Language C++ 20 (gcc 12.2)
Score 400
Code Size 785 Byte
Status AC
Exec Time 73 ms
Memory 8320 KiB

Compile Error

Main.cpp: In function ‘void slove()’:
Main.cpp:13:9: warning: unused variable ‘sum’ [-Wunused-variable]
   13 |     int sum=0;
      |         ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 1
AC × 30
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3416 KiB
01_handmade_00.txt AC 68 ms 8196 KiB
01_handmade_01.txt AC 38 ms 8104 KiB
01_handmade_02.txt AC 39 ms 8268 KiB
01_handmade_03.txt AC 72 ms 8268 KiB
01_handmade_04.txt AC 1 ms 3520 KiB
01_handmade_05.txt AC 18 ms 3420 KiB
02_random_00.txt AC 72 ms 8200 KiB
02_random_01.txt AC 72 ms 8244 KiB
02_random_02.txt AC 73 ms 8320 KiB
02_random_03.txt AC 71 ms 8196 KiB
02_random_04.txt AC 47 ms 3488 KiB
02_random_05.txt AC 48 ms 3644 KiB
02_random_06.txt AC 48 ms 3444 KiB
02_random_07.txt AC 47 ms 3520 KiB
02_random_08.txt AC 48 ms 3524 KiB
02_random_09.txt AC 48 ms 3448 KiB
02_random_10.txt AC 59 ms 3668 KiB
02_random_11.txt AC 58 ms 3676 KiB
02_random_12.txt AC 59 ms 3616 KiB
02_random_13.txt AC 58 ms 3744 KiB
02_random_14.txt AC 58 ms 3796 KiB
02_random_15.txt AC 59 ms 3588 KiB
02_random_16.txt AC 50 ms 3420 KiB
02_random_17.txt AC 47 ms 3524 KiB
02_random_18.txt AC 52 ms 3616 KiB
02_random_19.txt AC 47 ms 3648 KiB
02_random_20.txt AC 47 ms 3588 KiB
02_random_21.txt AC 48 ms 3400 KiB
02_random_22.txt AC 47 ms 3592 KiB