제출 #952161

#제출 시각아이디문제언어결과실행 시간메모리
952161SmuggingSpunJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
170 ms18768 KiB
#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]) << " "; } }

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

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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...