제출 #259484

#제출 시각아이디문제언어결과실행 시간메모리
259484ChrisTJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
156 ms11000 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main () {
	int n;
	scanf ("%d",&n);
	vector<pii> v(n+1); vector<int> ans(n+1), a(n);
	for (int i = 0; i <= n; i++) scanf ("%d",&v[i].first), v[i].second = i;
	for (auto &au : a) scanf ("%d",&au);
	sort(v.begin(),v.end());
	sort(a.begin(),a.end());
	vector<int> pma(n), sma(n);
	pma[0] = max(0,v[0].first - a[0]);
	for (int i = 0; i < n; i++) pma[i] = max(pma[i-1],v[i].first - a[i]);
	sma[n-1] = max(0,v[n].first - a[n-1]);
	for (int i = n-2; i >= 0; i--) sma[i] = max(sma[i+1],v[i+1].first - a[i]);
	for (int i = 0; i <= n; i++) {
		ans[v[i].second] = max(i ? pma[i-1] : 0,i == n ? 0 : sma[i]);
	}
	for (int i = 0; i <= n; i++) printf ("%d%c",ans[i]," \n"[i==n]);
	return 0;
}

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

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&n);
  ~~~~~~^~~~~~~~~
ho_t1.cpp:9:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i <= n; i++) scanf ("%d",&v[i].first), v[i].second = i;
                               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t1.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (auto &au : a) scanf ("%d",&au);
                     ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...