제출 #203514

#제출 시각아이디문제언어결과실행 시간메모리
203514arman_ferdousJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
145 ms7164 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+100;

int n;
struct data{
	int x, idx;
}a[N];
int b[N];

int pre[N], suf[N], ans[N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n + 1; i++) {
		scanf("%d", &a[i].x);
		a[i].idx = i;
	} for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
	sort(a + 1, a + n + 2, [&](data a, data b) {
		return a.x < b.x;
	});
	sort(b + 1, b + n + 1);

	for(int i = 1; i <= n; i++) 
		pre[i] = max(a[i].x - b[i], 0);
	for(int i = n; i > 0; i--)
		suf[i] = max(a[i + 1].x - b[i], 0);
	for(int i = 2; i <= n; i++) pre[i] = max(pre[i], pre[i - 1]);
	for(int i = n - 1; i > 0; i--) suf[i] = max(suf[i], suf[i + 1]);

	for(int i = 1; i <= n + 1; i++) {
		ans[a[i].idx] = max(pre[i - 1], suf[i]);
	} for(int i = 1; i <= n + 1; i++)
		printf("%d ", ans[i]);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
ho_t1.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i].x);
   ~~~~~^~~~~~~~~~~~~~~
ho_t1.cpp:19:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  } for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
                                ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...