답안 #762950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762950 2023-06-22T01:40:47 Z vjudge1 Just Long Neckties (JOI20_ho_t1) C++14
0 / 100
0 ms 340 KB
#include<bits/stdc++.h>
#define BUG(x) cerr << #x << " = " << x << endl
using namespace std;
const int N = 200005;
int t,n,a[N],b[N],st[2][4*N],diff[2][N];
void build(int id, int l, int r, int idx) {
	if (l>r) return;
	if (l==r) {
		st[idx][id] = diff[idx][l];
		return;
	}
	int m = (l+r)/2;
	build(id*2,l,m,idx);
	build(id*2+1,m+1,r,idx);
	st[idx][id] = max(st[idx][id*2],st[idx][id*2+1]);
}
int get(int id, int l, int r, int u, int v, int idx) {
	if (l>v || r<u) return 0;
	if (l>=u && r<=v) return st[idx][id];
	int m = (l+r)/2;
	return max(get(id*2,l,m,u,v,idx),get(id*2+1,m+1,r,u,v,idx));
}
void solve() {
	cin >> n;
	for (int i = 0; i<=n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i<n; i++) {
		cin >> b[i];
	}
	sort(a,a+n+1);
	sort(b,b+n);
//	for (int i = 0; i<n+1; i++) {
//		cout << a[i] << " ";
//	}
//	cout << endl;
//	for (int i = 0; i<n; i++) {
//		cout << b[i] << " ";
//	}
//	cout << endl;
	for (int i = 1; i<=n; i++) {
		diff[0][i] = max(a[i-1]-b[i-1],0);
		diff[1][i] = max(a[i]-b[i-1],0);
//		BUG(diff[0][i]);
//		BUG(diff[1][i]);
	}
	build(1,1,n,0);
	build(1,1,n,1);
	cout << get(1,1,n,1,n,1) << " ";	
	for (int i = 2; i<=n; i++) {
		cout << max(get(1,1,n,1,i-1,0), get(1,1,n,i,n,1)) << " ";
	}
	cout << get(1,1,n,1,n,0) << " ";
}
signed main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -