제출 #445612

#제출 시각아이디문제언어결과실행 시간메모리
445612jamezzzJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
144 ms7920 KiB
#include <bits/stdc++.h>
using namespace std;

int n, a, b[200005], c[200005], pmx[200005], smx[200005];
typedef pair<int, int> ii;
vector<ii> v;

int main(){
    scanf("%d", &n);
    for (int i = 0; i <= n; ++i){
        scanf("%d", &a);
        v.push_back(ii(a, i));
    }
    for (int i = 0; i < n; ++i){
        scanf("%d", &b[i]);
    }
    sort(v.begin(), v.end());
    sort(b, b + n);
    int ans = 0;
    for (int i = 1; i <= n; ++i){
        ans = max(ans, v[i].first - b[i - 1]);
        c[v[0].second] = ans;
    }
    int sfx = 0;
    for (int i = n; i >= 1; --i){
        sfx = max(sfx, v[i].first - b[i - 1]);
        smx[i] = sfx;
    }
    smx[n + 1] = 0;
    for (int i = 1; i <= n; ++i){
        pmx[i] = max(pmx[i - 1], v[i - 1].first - b[i - 1]);
        c[v[i].second] = max(pmx[i], smx[i + 1]);
    }
    for (int i = 0; i <= n; ++i){
        printf("%d ", c[i]);
    }

}

컴파일 시 표준 에러 (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:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
ho_t1.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...