Submission #635624

#TimeUsernameProblemLanguageResultExecution timeMemory
635624aris12345678Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
115 ms11064 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define X first #define Y second int main() { int n; scanf("%d", &n); vector<pii> a(n+1); vector<int> b(n); for(int i = 0; i <= n; i++) { scanf("%d", &a[i].X); a[i].Y = i; } for(int i = 0; i < n; i++) scanf("%d", &b[i]); sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector<int> pref; pref.push_back(max(a[0].X-b[0], 0)); for(int i = 1; i < n; i++) pref.push_back(max(pref.back(), a[i].X-b[i])); // for(int i = 0; i < n; i++) // printf("%d ", pref[i]); // printf("\n"); vector<int> suf; suf.push_back(max(a[n].X-b[n-1], 0)); for(int i = n-2; i >= 0; i--) suf.push_back(max(suf.back(), a[i+1].X-b[i])); reverse(suf.begin(), suf.end()); // for(int i = 0; i < n; i++) // printf("%d ", suf[i]); // printf("\n"); vector<int> ans(n+1); for(int i = 0; i <= n; i++) { if(i == 0) ans[a[i].Y] = suf[i]; else if(i == n) ans[a[i].Y] = pref[i-1]; else { ans[a[i].Y] = max(pref[i-1], suf[i]); // cout << a[i].Y << " " << pref[i-1] << " " << suf[i] << "\n"; } } for(int i = 0; i <= n; i++) printf("%d ", ans[i]); printf("\n"); return 0; }

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
ho_t1.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d", &a[i].X);
      |         ~~~~~^~~~~~~~~~~~~~~
ho_t1.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...