Submission #1114936

# Submission time Handle Problem Language Result Execution time Memory
1114936 2024-11-19T20:00:28 Z AdamGS Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
81 ms 8640 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<pair<int, int>> a;
    vector<int> b;
    int n, push_a, sum_a = 0, sum_b = 0;
    cin >> n;
    for(int i = 0; i <= n; i++){
        cin >> push_a;
        sum_a += push_a;
        a.push_back({push_a, i});
    }
    for(int i = 0; i < n; i++){
        cin >> push_a;
        sum_b += push_a;
        b.push_back(push_a);
    }
    sort(b.begin(), b.end());
    sort(a.begin(), a.end());
    /*
    int pomoc = a[0].first;
    a[0].first = 0;
    int k = 0;
    for(int j = 0; j <= n; j++){
        if(a[j].first == 0){
            j++;
        }
        cout << a[j].first << " " << b[k] << endl;
        wyn += max(0, a[j].first - b[k]);
        k++;
    }
    int tab[n + 1];
    tab[a[0].second] = wyn;
    cout << a[0].second << " " << wyn << endl;

    for(int i = 0; i < n; i++){
        wyn -= max(0, (a[i + 1].first - b[i]));
        wyn += max(0, (a[i].first - b[i]));
        tab[a[i + 1].second] = wyn;
    }
    for(int i = 0; i <= n; i++){
        cout << tab[i] << " ";
    }
    */
    int pref[n + 1], suf[n + 1], tab[n + 1];
    pref[0] = 0;
    suf[n] = 0;
    int max_pref_suf = 0;
    for(int i = 1; i <= n; i++){
        pref[i] = max(max_pref_suf, a[i - 1].first - b[i - 1]);
        max_pref_suf = pref[i];
    }
    max_pref_suf = 0;
    for(int i = n - 1; i >= 0; i--){
        suf[i] = max(max_pref_suf, a[i + 1].first - b[i]);
        max_pref_suf = suf[i];
    }
    for(int i = 0; i <= n; i++){
        tab[a[i].second] = max(pref[i], suf[i]);
    }
    for(int i = 0; i <= n; i++){
        cout << tab[i] << " ";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 71 ms 7872 KB Output is correct
34 Correct 73 ms 8044 KB Output is correct
35 Correct 69 ms 7872 KB Output is correct
36 Correct 71 ms 8384 KB Output is correct
37 Correct 81 ms 8640 KB Output is correct
38 Correct 70 ms 8384 KB Output is correct
39 Correct 66 ms 7616 KB Output is correct
40 Correct 70 ms 7616 KB Output is correct
41 Correct 74 ms 7616 KB Output is correct
42 Correct 71 ms 7628 KB Output is correct
43 Correct 66 ms 7624 KB Output is correct
44 Correct 69 ms 7316 KB Output is correct
45 Correct 68 ms 7360 KB Output is correct
46 Correct 65 ms 7368 KB Output is correct
47 Correct 61 ms 7124 KB Output is correct
48 Correct 64 ms 7004 KB Output is correct
49 Correct 71 ms 7616 KB Output is correct
50 Correct 67 ms 7616 KB Output is correct
51 Correct 69 ms 7616 KB Output is correct
52 Correct 69 ms 7784 KB Output is correct
53 Correct 70 ms 7644 KB Output is correct