#ifdef MINHDEPTRAI
#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/bits/stdc++.h"
#include <chrono>
#define __gcd(a, b) gcd(a, b)
using namespace std ::chrono;
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define foru(i, a, b) for(int i = a; i <= b; ++i)
#define ford(i, a, b) for(int i = a; i >= b; --i)
#define IOS ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define int long long
const int maxN = 2e6 + 5;
const int mod = 998244353;
const long long inf = 1e17;
int n, arr[maxN], b[maxN], ans[maxN], suffix[maxN], prefix[maxN];
pair<int, int> number[maxN];
bool used[maxN];
bool cmp(pair<int, int> a, pair<int, int> b){
if(a.first == b.first) return a.second < b.second;
return a.first < b.first;
}
signed main(){
// freopen("input.txt", "r", stdin);
// freopen("output1.txt", "w", stdout);
// input
IOS
cin >> n;
foru(i, 1, n + 1) {
cin >> arr[i];
number[i] = mp(arr[i], i);
}
foru(i, 1, n){
cin >> b[i];
}
sort(number + 1, number + 2 + n);
sort(b + 1, b + 1 + n);
prefix[0] = 0;
foru(i, 1, n){
prefix[i] = max( prefix[i - 1], max(number[i].first - b[i], 0ll));
}
suffix[n + 1] = 0;
ford(i, n, 1){
suffix[i] = max(suffix[i + 1], max(number[i + 1].first - b[i], 0ll));
}
foru(i, 1, n + 1){
ans[number[i].second] = max({prefix[i - 1], suffix[i], 0ll});
}
foru(i, 1, n + 1) cout << ans[i] << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
388 KB |
Output is correct |
19 |
Correct |
1 ms |
392 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
528 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
396 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
388 KB |
Output is correct |
19 |
Correct |
1 ms |
392 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
528 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
396 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
76 ms |
12744 KB |
Output is correct |
34 |
Correct |
85 ms |
13320 KB |
Output is correct |
35 |
Correct |
77 ms |
12864 KB |
Output is correct |
36 |
Correct |
79 ms |
13260 KB |
Output is correct |
37 |
Correct |
85 ms |
13572 KB |
Output is correct |
38 |
Correct |
75 ms |
13280 KB |
Output is correct |
39 |
Correct |
75 ms |
12416 KB |
Output is correct |
40 |
Correct |
85 ms |
12248 KB |
Output is correct |
41 |
Correct |
72 ms |
12452 KB |
Output is correct |
42 |
Correct |
71 ms |
12376 KB |
Output is correct |
43 |
Correct |
78 ms |
12344 KB |
Output is correct |
44 |
Correct |
82 ms |
11948 KB |
Output is correct |
45 |
Correct |
78 ms |
12068 KB |
Output is correct |
46 |
Correct |
88 ms |
11940 KB |
Output is correct |
47 |
Correct |
70 ms |
12088 KB |
Output is correct |
48 |
Correct |
68 ms |
12028 KB |
Output is correct |
49 |
Correct |
87 ms |
12632 KB |
Output is correct |
50 |
Correct |
74 ms |
12636 KB |
Output is correct |
51 |
Correct |
75 ms |
12716 KB |
Output is correct |
52 |
Correct |
74 ms |
12720 KB |
Output is correct |
53 |
Correct |
74 ms |
12680 KB |
Output is correct |