Submission #1051423

#TimeUsernameProblemLanguageResultExecution timeMemory
1051423manhlinh1501Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
65 ms10836 KiB
#include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; using i64 = long long; const int MAXN = 2e5 + 5; int N; pii a[MAXN]; int b[MAXN]; int prefix[MAXN]; int suffix[MAXN]; int ans[MAXN]; signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i <= N + 1; i++) { cin >> a[i].first; a[i].second = i; } for(int i = 1; i <= N; i++) cin >> b[i]; sort(a + 1, a + N + 2); sort(b + 1, b + N + 1); // for(int i = 1; i <= N + 1; i++) cout << a[i].first << " "; for(int i = 1, j = 1; i <= N; i++) { int x = a[j].first - b[i]; prefix[j] = max(prefix[j - 1], x); j++; } for(int i = N, j = N + 1; i >= 1; i--) { int x = a[j].first - b[i]; // cout << a[j].first << " " << b[i] << "\n"; suffix[j] = max(suffix[j + 1], x); j--; } for(int i = 1; i <= N + 1; i++) ans[a[i].second] = max(prefix[i - 1], suffix[i + 1]); for(int i = 1; i <= N + 1; i++) cout << ans[i] << " "; }

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...