답안 #740808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740808 2023-05-13T06:31:23 Z josanneo22 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
104 ms 10792 KB
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second

void solve(){
	int n; cin>>n;
	vector<int> a(n+1),b(n);
	for(auto&x:a) cin>>x;
	for(auto&x:b) cin>>x;
    vector<int> ord(n+1);
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[&](int i,int j){
        return a[i]<a[j];
    });
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
	vector<int> pre(n+2),suf(n+2);
	pre[0]=max(0,a[0]-b[0]);
	for(int i=1;i<n;i++){
		pre[i]=max(pre[i-1],max(0,a[i]-b[i]));
	}
	suf[n-1]=max(0,a[n]-b[n-1]);
	for(int i=n-2;i>=0;i--){
		suf[i]=max(suf[i+1],max(0,a[i+1]-b[i]));
	}
    vector<int> ans(n+1);
    for(int i=0;i<n;i++){
        ans[ord[i]]=max(pre[i-1],suf[i]);
    }
    ans[ord[n]]=pre[n-1];
    for(int i=0;i<=n;i++){
        cout<<ans[i]<<' ';
    }
    cout<<'\n';
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 368 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 368 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 96 ms 9936 KB Output is correct
34 Correct 100 ms 10316 KB Output is correct
35 Correct 97 ms 10040 KB Output is correct
36 Correct 96 ms 10528 KB Output is correct
37 Correct 103 ms 10792 KB Output is correct
38 Correct 103 ms 10672 KB Output is correct
39 Correct 98 ms 9684 KB Output is correct
40 Correct 103 ms 9764 KB Output is correct
41 Correct 99 ms 9768 KB Output is correct
42 Correct 98 ms 9888 KB Output is correct
43 Correct 98 ms 9752 KB Output is correct
44 Correct 97 ms 9340 KB Output is correct
45 Correct 99 ms 9364 KB Output is correct
46 Correct 99 ms 9292 KB Output is correct
47 Correct 76 ms 9428 KB Output is correct
48 Correct 74 ms 9416 KB Output is correct
49 Correct 101 ms 10068 KB Output is correct
50 Correct 104 ms 10076 KB Output is correct
51 Correct 102 ms 10072 KB Output is correct
52 Correct 104 ms 9996 KB Output is correct
53 Correct 103 ms 10040 KB Output is correct