Submission #1278004

#TimeUsernameProblemLanguageResultExecution timeMemory
1278004cjspd_olyJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
68 ms7132 KiB
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; using vii = vector<pii>; using vvii = vector<vii>; using l = long long; using vl = vector<l>; using vvl = vector<vl>; using vvvl = vector<vvl>; using pll = pair<l, l>; using vll = vector<pll>; using vvll = vector<vll>; using d = double; using vd = vector<d>; using vvd = vector<vd>; using vvvd = vector<vvd>; using ld = long double; using vld = vector<ld>; using vvld = vector<vld>; using vvvld = vector<vvld>; using vb = vector<bool>; using vvb = vector<vb>; using pbb = pair<bool, bool>; using vbb = vector<pbb>; #define ff first #define ss second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (!name.empty()) { (void)freopen((name + ".in").c_str(), "r", stdin); (void)freopen((name + ".out").c_str(), "w", stdout); } } const ld pi = 3.14159265358979323846; const l LINF = 1e18; const l INF = 1e9; const l MOD = 1e9 + 7; // const l MOD = 998244353; const l MAXN = 2e5 + 5; void solve() { int n; cin >> n; vii a(n + 1); vi b(n); for (int i = 0; i < n + 1; ++i) { cin >> a[i].first; a[i].second = i; } for (int i = 0; i < n; ++i) cin >> b[i]; sort(all(a)); sort(all(b)); vi pref(n + 1), suff(n + 1); pref[0] = a[0].first - b[0]; for (int i = 0; i < n + 1; ++i) pref[i] = max(pref[i - 1], max(a[i].first - b[i], 0)); suff[n - 1] = a[n].first - b[n - 1]; for (int i = n - 2; i >= 0; --i) suff[i] = max(suff[i + 1], a[i + 1].first - b[i]); vi res(n + 1); for (int k = 0; k <= n; ++k) { l left = (k == 0 ? LLONG_MIN : pref[k - 1]), // * all before k-1 right = (k == n ? LLONG_MIN : suff[k]); // * all after k res[a[k].second] = max({0LL, left, right}); } for (int i = 0; i <= n; ++i) cout << res[i] << " "; } int main() { setIO(""); #ifndef ONLINE_JUDGE // setIO("filename"); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }

Compilation message (stderr)

ho_t1.cpp: In function 'void setIO(std::string)':
ho_t1.cpp:52:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         (void)freopen((name + ".in").c_str(), "r", stdin);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.cpp:53:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         (void)freopen((name + ".out").c_str(), "w", stdout);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...