답안 #1047954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047954 2024-08-07T18:42:07 Z DeathIsAwe Just Long Neckties (JOI20_ho_t1) C++14
0 / 100
1000 ms 344 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long


int main() {
    int n; cin >> n;
    vector<int> newties(n+1), oldties(n), unsortednew;
    unordered_map<int,ll> ansmap, strange;
    for (int i=0;i<n+1;i++) {
        cin >> newties[i];
    }
    for (int i=0;i<n;i++) {
        cin >> oldties[i];
    }
    unsortednew = newties;


    sort(newties.begin(), newties.end());
    sort(oldties.begin(), oldties.end());
    priority_queue<ll> lol;
    ll ans = 0, dummy;
    for (int i=0;i<n;i++) {
        dummy = max(newties[i+1] - oldties[i], 0);
        if (strange.find(dummy) != strange.end()) {
            strange[dummy] += 1;
        } else {
            strange[dummy] = 1;
        }
        lol.push(dummy);
    }
    ansmap[newties[0]] = lol.top();
    for (int i=0;i<n;i++) {
        dummy = max(newties[i+1] - oldties[i], 0);
        strange[dummy] -= 1;
        dummy = max(newties[i] - oldties[i], 0);
        if (strange.find(dummy) != strange.end()) {
            strange[dummy] += 1;
        } else {
            strange[dummy] = 1;
        }
        while (strange[lol.top()] == 0) {
            lol.pop();
        }
        ansmap[newties[i+1]] = lol.top();
    }
    for (int i=0;i<n+1;i++) {
        cout << ansmap[unsortednew[i]] << ' ';
    }
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:22:8: warning: unused variable 'ans' [-Wunused-variable]
   22 |     ll ans = 0, dummy;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -