#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int>pi;
typedef pair<ll, ll>pl;
typedef vector<pi>vpi;
typedef vector<pl>vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
const long double PI = acos(-1);
const int oo = 2e9;
const int MOD = 998244353;
const int N = 2e5 + 7;
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define read(v) for (auto& it : v) scanf("%d", &it);
#define readL(v) for (auto& it : v) scanf("%lld", &it);
#define print(v) for (auto it : v) printf("%d ", it); puts("");
#define printL(v) for (auto it : v) printf("%lld ", it); puts("");
void solve() {
int n, m;
scanf("%d %d", &n, &m);
vl a(n), b(m);
readL(a);
readL(b);
sort(all(a)), sort(all(b));
ll ans = 0;
if (n == m) {
for (int i = 0; i < n; i++)
ans = max(ans, abs(a[i] - b[i]));
}
else if (n < m) {
vb vis(m);
for (int i = 0; i < n; i++) {
ll dif = oo, idx = -1;
for (int j = 0; j < m; j++)
if (abs(b[j] - a[i]) < dif)
dif = abs(b[j] - a[i]), idx = j;
vis[idx] = true, ans = max(ans, dif);
}
}
else {
vb vis(n);
for (int i = 0; i < m; i++) {
ll dif = oo, idx = -1;
for (int j = 0; j < n; j++)
if (abs(b[i] - a[j]) < dif)
dif = abs(b[i] - a[j]), idx = j;
vis[idx] = true, ans = max(ans, dif);
}
}
printf("%lld\n", ans);
}
int t = 1;
int main() {
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
//#endif
//scanf("%d", &t);
while (t--) solve();
}
Compilation message
cipele.cpp: In function 'void solve()':
cipele.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
cipele.cpp:24:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | #define readL(v) for (auto& it : v) scanf("%lld", &it);
| ~~~~~^~~~~~~~~~~~~
cipele.cpp:31:2: note: in expansion of macro 'readL'
31 | readL(a);
| ^~~~~
cipele.cpp:24:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | #define readL(v) for (auto& it : v) scanf("%lld", &it);
| ~~~~~^~~~~~~~~~~~~
cipele.cpp:32:2: note: in expansion of macro 'readL'
32 | readL(b);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2260 KB |
Output is correct |
2 |
Correct |
39 ms |
2272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
2308 KB |
Output is correct |
2 |
Correct |
37 ms |
2328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Incorrect |
21 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Incorrect |
21 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1031 ms |
1988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
2124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
1936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |