Submission #745501

#TimeUsernameProblemLanguageResultExecution timeMemory
745501sleepntsheepJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
113 ms11596 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
int n, b[N], c[N], p[N], s[N], ans[N];
pair<int, int> a[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n + 1; ++i) scanf("%d", &a[i].first), a[i].second = i;
    for (int i = 1; i <= n; ++i) scanf("%d", b+i);

    sort(a+1, a+2+n);
    sort(b+1, b+1+n);

    for (int i = 1; i <= n + 1; ++i) c[a[i].second] = i;

    for (int i = 1; i <= n + 1; ++i) {
        p[i] = max(p[i-1], max(0, a[i].first - b[i]));
    }

    for (int i = n + 1; i >= 1; --i) {
        s[i] = max(s[i+1], max(0, a[i].first - b[i - 1]));
    }

    for (int i = 1; i <= n + 1; ++i) {
        int j = c[i];
        ans[i] = max(p[j-1], s[j+1]);
        printf("%d ", ans[i]);
    }

    return 0;
}

Compilation message (stderr)

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
ho_t1.cpp:10:43: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     for (int i = 1; i <= n + 1; ++i) scanf("%d", &a[i].first), a[i].second = i;
      |                                      ~~~~~^~~~~~~~~~~~~~~~~~~
ho_t1.cpp:11:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for (int i = 1; i <= n; ++i) scanf("%d", b+i);
      |                                  ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...