Run ID Author Problem Lang Verdict Time Memory Code Length Submit Time
318112 gsh7013020 最大的和 T5 C++ Accepted 8 MS 1060 KB 1098 2026-04-19 16:45:20

Tests(10/10):


#include <bits/stdc++.h> using namespace std; template<typename U, typename V>bool cmin(U &x, const V &y) { return y < x ? x = y, 1 : 0; } template<typename U, typename V>bool cmax(U &x, const V &y) { return y > x ? x = y, 1 : 0; } //不听老人言,磕到甲沟炎 using ll = long long; using pii = pair<int, int>; using ull = unsigned long long; #define fi first #define ls i<<1 #define rs i<<1|1 #define fls i>>1 #define frs i-1>>1 #define endl '\n' #define se second #define int ll const int N = 5e4 + 10, inf = 0x3f3f3f3f; int a[N],b[N]; void solve() { int n,d; cin >> n>>d; 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=n,r=n; while(l>=1&&r>=1){ if (abs(a[l]-b[r])<=d){ cout <<a[l]+b[r]; return ; } else { if (a[l]>b[r]){ l--; } else{ r--; } } } cout <<"None"; } signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int T = 1; //cin >> T; while (T--) { solve(); } return 0; }


Judgement Protocol: