답안 #762925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762925 2023-06-22T01:27:41 Z vjudge1 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
96 ms 11656 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
using namespace std;

const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

int n;
int a[mxN], b[mxN], pref[mxN], suff[mxN], ans[mxN], idx[mxN];

void solve() {
	cin >> n;
	for(int i = 1; i <= n + 1; ++i) {
		cin >> a[i];
		idx[i] = i;
	}
	for(int i = 1; i <= n; ++i) cin >> b[i];
	sort(idx + 1, idx + n + 2, [&](int i, int j) {
		return a[i] < a[j];
	});
	sort(a + 1, a + n + 2);
	sort(b + 1, b + n + 1);
	for(int i = 1; i <= n; ++i) {
		pref[i] = max(pref[i - 1], max(a[i] - b[i], 0ll));
	}	
	for(int i = n + 1; i >= 2; --i) {
		suff[i] = max(suff[i + 1], max(a[i] - b[i - 1], 0ll));
	}
	for(int i = 1; i <= n + 1; ++i) {
		ans[idx[i]] = max(pref[i - 1], suff[i + 1]);
	}
	for(int i = 1; i <= n + 1; ++i)
		cout << ans[i] << " \n"[i == n + 1];
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int t = 1; //cin >> t;
	while(t--) solve();

#ifdef CDuongg
	auto end = chrono::high_resolution_clock::now();
	cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
	cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 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 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 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 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 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 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 81 ms 10680 KB Output is correct
34 Correct 85 ms 11212 KB Output is correct
35 Correct 91 ms 10840 KB Output is correct
36 Correct 84 ms 11264 KB Output is correct
37 Correct 87 ms 11656 KB Output is correct
38 Correct 89 ms 11536 KB Output is correct
39 Correct 83 ms 10580 KB Output is correct
40 Correct 91 ms 10496 KB Output is correct
41 Correct 84 ms 10576 KB Output is correct
42 Correct 87 ms 10536 KB Output is correct
43 Correct 86 ms 10528 KB Output is correct
44 Correct 82 ms 10164 KB Output is correct
45 Correct 82 ms 10188 KB Output is correct
46 Correct 83 ms 10168 KB Output is correct
47 Correct 62 ms 10184 KB Output is correct
48 Correct 62 ms 10136 KB Output is correct
49 Correct 85 ms 10784 KB Output is correct
50 Correct 96 ms 10764 KB Output is correct
51 Correct 85 ms 10868 KB Output is correct
52 Correct 87 ms 10828 KB Output is correct
53 Correct 86 ms 10836 KB Output is correct