Submission #296802

# Submission time Handle Problem Language Result Execution time Memory
296802 2020-09-10T22:03:51 Z Bruteforceman Just Long Neckties (JOI20_ho_t1) C++11
100 / 100
333 ms 19448 KB
#include "bits/stdc++.h"
using namespace std;
int n;
int a[200010], b[200010], aux[200010];
int pre[200010], suf[200010];

int solve(int p) {
	vector <int> u, v;
	for(int i = 1; i <= (n + 1); i++) {
		if(i != p) u.push_back(a[i]);
	}
	for(int i = 1; i <= n; i++) {
		v.push_back(b[i]);
	}
	sort(u.begin(), u.end());
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i < u.size(); i++) {
		ans = max(ans, u[i] - v[i]);
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	srand(time(NULL));
	scanf("%d", &n);
	map <int, int> id;
	for(int i = 1; i <= n+1; i++) {
		scanf("%d", &a[i]);
		aux[i] = a[i];
	}	
	for(int i = 1; i <= n; i++) {
		scanf("%d", &b[i]);
	}
	sort(a + 1, a + n + 2);
	sort(b + 1, b + n + 1);
	for(int i = 1; i <= n + 1; i++) {
		id[a[i]] = i;
	}
	for(int i = n+1; i >= 2; i--) {
		suf[i] = max(suf[i + 1], a[i] - b[i - 1]);
	}
	for(int i = 1; i <= n; i++) {
		pre[i] = max(pre[i - 1], a[i] - b[i]);
	}
	for(int i = 1; i <= n + 1; i++) {
		int x = id[aux[i]];
		printf("%d ", max(pre[x - 1], suf[x + 1]));
	}
	printf("\n");
	return 0;
}

Compilation message

ho_t1.cpp: In function 'int solve(int)':
ho_t1.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i = 0; i < u.size(); i++) {
      |                 ~~^~~~~~~~~~
ho_t1.cpp: In function 'int main(int, const char**)':
ho_t1.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
ho_t1.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
ho_t1.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   scanf("%d", &b[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 305 ms 18328 KB Output is correct
34 Correct 319 ms 19096 KB Output is correct
35 Correct 330 ms 18424 KB Output is correct
36 Correct 313 ms 18844 KB Output is correct
37 Correct 327 ms 19448 KB Output is correct
38 Correct 322 ms 19200 KB Output is correct
39 Correct 312 ms 18296 KB Output is correct
40 Correct 309 ms 18040 KB Output is correct
41 Correct 311 ms 18296 KB Output is correct
42 Correct 331 ms 18296 KB Output is correct
43 Correct 333 ms 18168 KB Output is correct
44 Correct 299 ms 17656 KB Output is correct
45 Correct 306 ms 17784 KB Output is correct
46 Correct 321 ms 17788 KB Output is correct
47 Correct 166 ms 10616 KB Output is correct
48 Correct 172 ms 10596 KB Output is correct
49 Correct 330 ms 18640 KB Output is correct
50 Correct 321 ms 18808 KB Output is correct
51 Correct 333 ms 18808 KB Output is correct
52 Correct 324 ms 18756 KB Output is correct
53 Correct 325 ms 18680 KB Output is correct