# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
855766 |
2023-10-01T18:31:03 Z |
vjudge1 |
Cipele (COCI18_cipele) |
C++17 |
|
32 ms |
3032 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,O3,unroll-loops")
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define vb vector<bool>
#define vvb vector<vb>
#define endl "\n"
#define sp << " " <<
#define F(i, s, n) for(int i = s; i < n; i++)
#define pb push_back
#define fi first
#define se second
int mod = 998244353;
int inf = LLONG_MAX >> 3;
int mult(int x, int y) {
return (x%mod)*(y%mod)%mod;
}
void solve() {
int n, m;
cin >> n >> m;
vi a(n), b(m);
F(i, 0, n) cin >> a[i];
F(i, 0, m) cin >> b[i];
if(n > m) {
swap(a, b);
swap(n, m);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vi selected;
stack<int> s;
int st = 0;
int bg = 0;
F(i, 0, n) {
auto p = lower_bound(next(b.begin(), bg), b.end(), a[i]);
if(p == b.end()) p--;
if(p != next(b.begin(), bg) && abs(*(p-1) - a[i]) < abs(*p - a[i])) {
p--;
}
if(!s.empty() && abs(s.top() - a[i]) < abs(*p - a[i])) {
//cout << "dasda" << endl;
selected.pb(s.top());
s.pop();
} else {
selected.pb(*p);
bg = p - b.begin() + 1;
F(j, st, bg-1) s.push(b[j]);
st = bg;
}
}
sort(selected.begin(), selected.end());
//F(i, 0, n) cout << selected[i] << endl;
int ans = 0;
F(i, 0, n) {
ans = max(ans, abs(a[i] - selected[i]));
}
cout << ans;
}
void setIO() {
ios::sync_with_stdio(0); cin.tie(0);
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
signed main() {
setIO();
int t = 1;
//cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3032 KB |
Output is correct |
2 |
Incorrect |
31 ms |
3024 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
2960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
2840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
2792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |