#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 = accumulate(a.begin(), a.end(), 0ll);
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
cipele.cpp: In function 'int main()':
cipele.cpp:49:19: error: 'accumulate' was not declared in this scope
long long sum = accumulate(a.begin(), a.end(), 0ll);
^~~~~~~~~~