# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100428 | cvele | Cipele (COCI18_cipele) | C++14 | 126 ms | 3856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
using namespace std;
const int N = 100005;
int n, m;
long long pref[N];
vector <int> a, b;
long long ss(int x, int y) {
return (pref[y] - (x > 0 ? pref[x - 1] : 0));
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
b.push_back(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (b.size() < a.size()) {
swap(a, b);
swap(n, m);
}
long long sum = 0;
for (int i = 0; i < a.size(); i++) sum += a[i];
pref[0] = b[0];
for (int i = 1; i < m; i++) {
pref[i] = pref[i - 1] + b[i];
}
long long ans = 2e18;
int w;
for (int i = n - 1; i < m; i++) {
if (abs(sum - ss(i - n + 1, i)) < ans) {
ans = abs(sum - ss(i - n + 1, i));
w = i;
}
}
ans = -2e9;
int ce = 0;
for (int i = w - n + 1; i <= w; i++) {
ans = max((int) ans, abs(a[ce++] - b[i]));
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |