Submission #67005422
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, j, k) for(int i = (j); i <= (k); i ++)
#define per(i, j, k) for(int i = (j); i >= (k); i --)
#define pb emplace_back
#define fi first
#define se second
using vi = vector<int>;
using pi = pair<int,int>;
template<typename T0, typename T1> bool chmin(T0 &x, const T1 &y){
if(y < x){x = y; return true;} return false;
}
template<typename T0, typename T1> bool chmax(T0 &x, const T1 &y){
if(y > x){x = y; return true;} return false;
}
template<typename T> void debug(char *s, T x){
cerr<< s <<" = "<< x <<endl;
}
template<typename T, typename ...Ar> void debug(char *s, T x, Ar... y){
int dep = 0;
while(!(dep == 0 && *s == ',')){
if(*s == '(') dep++;
if(*s == ')') dep--;
cerr << *s++;
}
cerr <<" = "<< x <<",";
debug(s + 1, y...);
}
#define gdb(...) debug((char*)#__VA_ARGS__, __VA_ARGS__)
void solve(){
int n, m;
cin >> n >> m;
vi a(n), b(n);
for(auto &x:a) cin >> x;
for(auto &x:b) cin >> x;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
auto chk = [&](int p){
for(int i = p, j = n - 1; i < n; i++, j--){
if(a[i] + b[j] < m) return false;
}
return true;
};
int l = 0, r = n;
while(l < r){
int mid = (l + r) / 2;
if(chk(mid)){
r = mid;
}
else{
l = mid + 1;
}
}
int ans = 0;
for(int i = 0, j = l - 1; i < l; i++, j--){
chmax(ans, (a[i] + b[j]) % m);
}
for(int i = l, j = n - 1; i < n; i++, j--){
chmax(ans, (a[i] + b[j]) % m);
}
cout << ans <<'\n';
}
signed main(){
#ifdef LOCAL
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
Submission Info
| Submission Time |
|
| Task |
D - Match, Mod, Minimize |
| User |
bananabot |
| Language |
C++ 23 (Clang 16.0.6) |
| Score |
700 |
| Code Size |
1767 Byte |
| Status |
AC |
| Exec Time |
76 ms |
| Memory |
5444 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
700 / 700 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample-01.txt |
| All |
01-01.txt, 01-02.txt, 01-03.txt, 01-05.txt, 01-06.txt, 01-07.txt, 02-01.txt, 02-02.txt, 02-03.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 04-01.txt, 04-02.txt, 05-01.txt, 05-02.txt, 05-03.txt, 05-04.txt, 05-05.txt, 05-06.txt, sample-01.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01-01.txt |
AC |
60 ms |
3484 KiB |
| 01-02.txt |
AC |
54 ms |
3332 KiB |
| 01-03.txt |
AC |
47 ms |
3468 KiB |
| 01-05.txt |
AC |
48 ms |
3608 KiB |
| 01-06.txt |
AC |
55 ms |
3428 KiB |
| 01-07.txt |
AC |
65 ms |
3556 KiB |
| 02-01.txt |
AC |
76 ms |
5340 KiB |
| 02-02.txt |
AC |
74 ms |
5404 KiB |
| 02-03.txt |
AC |
72 ms |
5416 KiB |
| 03-01.txt |
AC |
73 ms |
5428 KiB |
| 03-02.txt |
AC |
73 ms |
5368 KiB |
| 03-03.txt |
AC |
73 ms |
5440 KiB |
| 03-04.txt |
AC |
74 ms |
5312 KiB |
| 03-05.txt |
AC |
72 ms |
5368 KiB |
| 04-01.txt |
AC |
38 ms |
5396 KiB |
| 04-02.txt |
AC |
25 ms |
5412 KiB |
| 05-01.txt |
AC |
42 ms |
5412 KiB |
| 05-02.txt |
AC |
38 ms |
5444 KiB |
| 05-03.txt |
AC |
41 ms |
5416 KiB |
| 05-04.txt |
AC |
41 ms |
5256 KiB |
| 05-05.txt |
AC |
69 ms |
5392 KiB |
| 05-06.txt |
AC |
71 ms |
5256 KiB |
| sample-01.txt |
AC |
1 ms |
3400 KiB |