#include <bits/stdc++.h>
#define int long long
using namespace std;
/*
* Si prend plus petit : cout = 0
* sinon cout > 0
* Si N de chaque côté :
* a_1 <= ... <= a_n
* b_1 <= ... <= b_n
* Si b_1 <= a_1 : mieux de mettre avec a_1
* Sinon b_1 > a_1 :
* SI on met a_1 avec b_i, i > 1 et b_1 avec j, j > 1
* cout : max(bi - a1, max(b1 - aj, 0))
* S max(bi-aj, 0) = 0 : mieux echanger
* Tri par ordre croissant !
*/
signed main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int N;
cin >> N;
vector<pair<int, int>> A(N+1);
vector<int> B(N);
for (int i(0); i <= N; ++i)
{
cin >> A[i].first;
A[i].second = i;
}
for (auto &v : B) cin >> v;
sort(A.begin(), A.end());
sort(B.begin(), B.end());
vector<int> sol(N+1);
for (int toSkip(0); toSkip <= N; ++toSkip)
for (int i(0); i < N; ++i)
sol[A[toSkip].second] = max(sol[A[toSkip].second], -B[i] + A[i + (toSkip<=i)].first);
for (auto v: sol)
cout << v<< ' ';
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
4 ms |
364 KB |
Output is correct |
15 |
Correct |
9 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
14 ms |
620 KB |
Output is correct |
18 |
Correct |
12 ms |
492 KB |
Output is correct |
19 |
Correct |
13 ms |
492 KB |
Output is correct |
20 |
Correct |
11 ms |
512 KB |
Output is correct |
21 |
Correct |
11 ms |
492 KB |
Output is correct |
22 |
Correct |
11 ms |
492 KB |
Output is correct |
23 |
Correct |
11 ms |
492 KB |
Output is correct |
24 |
Correct |
12 ms |
492 KB |
Output is correct |
25 |
Correct |
15 ms |
492 KB |
Output is correct |
26 |
Correct |
14 ms |
492 KB |
Output is correct |
27 |
Correct |
14 ms |
492 KB |
Output is correct |
28 |
Correct |
15 ms |
492 KB |
Output is correct |
29 |
Correct |
12 ms |
492 KB |
Output is correct |
30 |
Correct |
14 ms |
492 KB |
Output is correct |
31 |
Correct |
16 ms |
492 KB |
Output is correct |
32 |
Correct |
17 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
4 ms |
364 KB |
Output is correct |
15 |
Correct |
9 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
14 ms |
620 KB |
Output is correct |
18 |
Correct |
12 ms |
492 KB |
Output is correct |
19 |
Correct |
13 ms |
492 KB |
Output is correct |
20 |
Correct |
11 ms |
512 KB |
Output is correct |
21 |
Correct |
11 ms |
492 KB |
Output is correct |
22 |
Correct |
11 ms |
492 KB |
Output is correct |
23 |
Correct |
11 ms |
492 KB |
Output is correct |
24 |
Correct |
12 ms |
492 KB |
Output is correct |
25 |
Correct |
15 ms |
492 KB |
Output is correct |
26 |
Correct |
14 ms |
492 KB |
Output is correct |
27 |
Correct |
14 ms |
492 KB |
Output is correct |
28 |
Correct |
15 ms |
492 KB |
Output is correct |
29 |
Correct |
12 ms |
492 KB |
Output is correct |
30 |
Correct |
14 ms |
492 KB |
Output is correct |
31 |
Correct |
16 ms |
492 KB |
Output is correct |
32 |
Correct |
17 ms |
492 KB |
Output is correct |
33 |
Execution timed out |
1071 ms |
9964 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |