Submission #762931

# Submission time Handle Problem Language Result Execution time Memory
762931 2023-06-22T01:29:28 Z Antonn_114 Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
1 ms 340 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <utility>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> a(n + 1);
	vector<int> b(n);
	for (int i = 0; i < n + 1; i ++){
		scanf("%d", &a[i].first);
		a[i].second = i;
	}
	for (int i = 0; i < n ; i++){
		scanf("%d", &b[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	vector<int> res(n + 1);
	vector<int> max_diff_cross(n);
	for (int i = n; i >= 1; i--){
		max_diff_cross[i] = abs(a[i].first - b[i - 1]);
		if (i != n) max_diff_cross[i] = max(max_diff_cross[i], max_diff_cross[i + 1]);
	}
	int max_diff_straight = 0;
	for (int i = 0; i <= n; i++){
		res[a[i].second] = max(i != n ? max_diff_cross[i + 1] : 0, max_diff_straight);
		max_diff_straight = max(max_diff_straight, abs(a[i].first - b[i]));
	}
	for (int i = 0; i <= n; i++){
		printf("%d ", res[i]);
	}
	return 0;
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
ho_t1.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d", &a[i].first);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
ho_t1.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &b[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -