답안 #952161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952161 2024-03-23T07:35:32 Z SmuggingSpun Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
170 ms 18768 KB
#include<bits/stdc++.h>
#define taskname "justlongneckties"
using namespace std;
const int lim = 2e5 + 5;
const int INF = 1e9;
template<class T>void maximize(T& a, T b){
	if(a < b){
		a = b;
	}
}
int n, a[lim], b[lim], p[lim], ans[lim];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	int n;
	cin >> n;
	for(int i = 0; i <= n; ){
		cin >> a[++i];
	}
	for(int i = 1; i <= n; i++){
		cin >> b[i];
	}
	sort(b + 1, b + n + 1);
	iota(p + 1, p + n + 2, 1);
	sort(p + 1, p + n + 2, [&] (int i, int j) -> bool{
		return a[i] < a[j];
	});
	multiset<int>right;
	int left = -INF;
	for(int i = 1; i <= n; i++){
		right.insert(a[p[i + 1]] - b[i]);
	}
	ans[p[1]] = *right.rbegin();
	for(int i = 2; i <= n + 1; i++){
		right.erase(right.find(a[p[i]] - b[i - 1]));
		maximize(left, a[p[i - 1]] - b[i - 1]);
		ans[p[i]] = max(right.empty() ? 0 : *right.rbegin(), left);
	}
	for(int i = 0; i <= n; ){
		cout << max(0, ans[++i]) << " ";
	}
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 3 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 3 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 121 ms 17492 KB Output is correct
34 Correct 124 ms 18232 KB Output is correct
35 Correct 117 ms 17580 KB Output is correct
36 Correct 121 ms 18092 KB Output is correct
37 Correct 123 ms 18768 KB Output is correct
38 Correct 119 ms 18512 KB Output is correct
39 Correct 163 ms 17448 KB Output is correct
40 Correct 162 ms 17492 KB Output is correct
41 Correct 162 ms 17788 KB Output is correct
42 Correct 156 ms 17448 KB Output is correct
43 Correct 158 ms 17492 KB Output is correct
44 Correct 97 ms 16984 KB Output is correct
45 Correct 103 ms 17008 KB Output is correct
46 Correct 97 ms 16804 KB Output is correct
47 Correct 88 ms 17236 KB Output is correct
48 Correct 90 ms 17340 KB Output is correct
49 Correct 164 ms 17768 KB Output is correct
50 Correct 162 ms 18000 KB Output is correct
51 Correct 170 ms 18000 KB Output is correct
52 Correct 168 ms 18004 KB Output is correct
53 Correct 167 ms 18004 KB Output is correct