# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566924 | 1zaid1 | Just Long Neckties (JOI20_ho_t1) | C++14 | 1093 ms | 300 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 <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 1e5 + 5, MOD = 1e9+7;
int check(vector<int>&a, vector<int>&b) {
sort(a.begin(), a.end());
int ans = INT_MAX;
do {
int cur = 0;
for (int i = 0; i < a.size(); i++) {
cur = max(cur, max(a[i]-b[i], 0ll));
} ans = min(ans, cur);
} while (next_permutation(a.begin(), a.end()));
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
srand(time(0));
int n;
cin >> n;
vector<int> a(n+1), b(n);
for (int&i:a) cin >> i;
for (int&i:b) cin >> i;
for (int i = 0; i <= n; i++) {
auto tmp = a;
swap(tmp[i], tmp[n]);
tmp.pop_back();
cout << check(tmp, b) << ' ';
} cout << endl;
return 0;
}
/*
3
4 3 7 6
2 6 4
5
4 7 9 10 11 12
3 5 7 9 11
*/
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... |