답안 #1045064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045064 2024-08-05T16:21:35 Z Nurislam Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
88 ms 13952 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

#define int long long

template <class F, class _S>
bool chmin(F &u, const _S &v){
	bool flag = false;
	if ( u > v ){
		u = v; flag |= true;
	}
	return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
	bool flag = false;
	if ( u < v ){
		u = v; flag |= true;
	}
	return flag;
}
const int N = 2e5+5, inf = 1e18, mod = 1e9+7;

void solve(){
	int n;
	cin >> n;
	vector<array<int,2>> a(n+1);
	int id = 0;
	for(auto &[i, j]:a){
		cin >> i;
		j = id++;
	}
	vector<int> b(n);
	for(int &i:b)cin >> i;
	
	
	sort(all(a));
	sort(all(b));
	//for(auto i:a)cout << i[0] << ' ';
	//cout << '\n';
	//for(auto i:b)cout << i << ' ';
	//cout << '\n';
	
	vector<int> suf(n+2, 0);
	for(int i = n; i > 0; i--){
		chmax(suf[i], suf[i+1]);
		chmax(suf[i], a[i][0] - b[i-1]);
	}
	//for(int i = 1; i <= n; i++)cout << suf[i] << ' ';
	//cout << '\n';
	int pre = 0;
	vector<int> ans(n+1);
	for(int i = 0; i <= n; i++){
		ans[a[i][1]] = max(pre, suf[i+1]);
		chmax(pre, a[i][0] - b[i]);
	}
	
	for(int i:ans)cout << i << ' ';
	cout << '\n';
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 540 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 540 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 61 ms 12884 KB Output is correct
34 Correct 74 ms 13660 KB Output is correct
35 Correct 59 ms 13140 KB Output is correct
36 Correct 58 ms 13648 KB Output is correct
37 Correct 77 ms 13952 KB Output is correct
38 Correct 73 ms 13752 KB Output is correct
39 Correct 64 ms 12828 KB Output is correct
40 Correct 63 ms 12700 KB Output is correct
41 Correct 69 ms 12952 KB Output is correct
42 Correct 63 ms 12928 KB Output is correct
43 Correct 57 ms 12880 KB Output is correct
44 Correct 88 ms 12268 KB Output is correct
45 Correct 55 ms 12540 KB Output is correct
46 Correct 56 ms 12344 KB Output is correct
47 Correct 71 ms 12628 KB Output is correct
48 Correct 52 ms 12628 KB Output is correct
49 Correct 66 ms 13180 KB Output is correct
50 Correct 61 ms 13140 KB Output is correct
51 Correct 58 ms 13136 KB Output is correct
52 Correct 57 ms 13300 KB Output is correct
53 Correct 74 ms 13212 KB Output is correct