Submission #745495

# Submission time Handle Problem Language Result Execution time Memory
745495 2023-05-20T08:41:01 Z sleepntsheep Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
1 ms 340 KB
#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], abs(a[i].first - b[i]));
    }

    for (int i = n + 1; i >= 1; --i) {
        s[i] = max(s[i+1], abs(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

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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -