Submission #1042256

# Submission time Handle Problem Language Result Execution time Memory
1042256 2024-08-02T17:57:06 Z dpsaveslives Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N; cin >> N;
    vector<pair<int,int>> A(N+1); vector<int> ord(N+1);
    for(int i = 0;i<=N;++i){
        cin >> A[i].f;
        A[i].s = i;
    }
    vector<int> B(N);
    for(int i = 0;i<N;++i){
        cin >> B[i];
    }
    sort(A.begin(),A.end()); sort(B.begin(),B.end());
    for(int i = 0;i<=N;++i) ord[i] = A[i].s;
    vector<int> pref(N);
    for(int i = 0;i<N;++i){
        if(i > 0) pref[i] = max(pref[i-1],max(A[i].f-B[i],0));
        else pref[i] = max(A[i].f-B[i],0);
    }
    vector<int> suf(N); //suf[N-1] starts at the last value of B and this time also the last value of A, so i+1 for A
    for(int i = N-1;i>=0;--i){
        if(i < N-1) suf[i] = max(suf[i+1],max(A[i+1].f-B[i],0));
        else suf[i] = max(A[i+1].f-B[i],0);
    }
    for(int i = 0;i<=N;++i){
        if(ord[i] == 0){
            cout << suf[0];
        }
        else if(ord[i] == N){
            cout << pref[N-1];
        }
        else{
            cout << max(pref[ord[i]-1],suf[ord[i]]);
        }
        if(i != N) cout << " ";
        else cout << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -