Submission #919750

# Submission time Handle Problem Language Result Execution time Memory
919750 2024-02-01T15:20:09 Z ByeWorld Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
82 ms 17912 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long 
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 2e5+10;
const int MAXK = 2010;
const int LOG = 20;
const int MOD = 1e9+7;
const int SQRT = 520;
const int INF = 1e9+10;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;

int n;
int a[MAXN], b[MAXN], ans[MAXN];
int pr[MAXN], su[MAXN];
vector <pii> vec;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=0; i<=n; i++){
        cin >> a[i]; vec.pb({a[i], i});
    }
    sort(vec.begin(), vec.end());
    for(int i=0; i<n; i++) cin >> b[i];
    sort(b+0, b+n);

    for(int i=0; i<=n-1; i++){
        if(i!=0) pr[i] = pr[i-1];
        pr[i] = max(pr[i], vec[i].fi-b[i]);
        //cout << i << ' ' << pr[i] << " p\n";
    }
    for(int i=n; i>=1; i--){
        su[i] = su[i+1];
        su[i] = max(su[i], vec[i].fi-b[i-1]);
        //cout << i << ' ' << su[i] << " p\n";
    }

    for(int i=0; i<=n; i++){ // kalo i ilang
        int num = 0;
        if(i!=0) num = pr[i-1];
        num = max(num, su[i+1]);
        ans[vec[i].se] = num;
    }

    for(int i=0; i<n+1; i++) cout << ans[i] << " \n"[i==n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 4 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4696 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 4 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4440 KB Output is correct
25 Correct 2 ms 4440 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
33 Correct 70 ms 16192 KB Output is correct
34 Correct 74 ms 16708 KB Output is correct
35 Correct 71 ms 16828 KB Output is correct
36 Correct 72 ms 17912 KB Output is correct
37 Correct 76 ms 17208 KB Output is correct
38 Correct 82 ms 17336 KB Output is correct
39 Correct 71 ms 16684 KB Output is correct
40 Correct 73 ms 16072 KB Output is correct
41 Correct 72 ms 16828 KB Output is correct
42 Correct 72 ms 16708 KB Output is correct
43 Correct 73 ms 16316 KB Output is correct
44 Correct 69 ms 15808 KB Output is correct
45 Correct 70 ms 15804 KB Output is correct
46 Correct 69 ms 15576 KB Output is correct
47 Correct 69 ms 15804 KB Output is correct
48 Correct 66 ms 15948 KB Output is correct
49 Correct 73 ms 16336 KB Output is correct
50 Correct 75 ms 16572 KB Output is correct
51 Correct 73 ms 17240 KB Output is correct
52 Correct 75 ms 17124 KB Output is correct
53 Correct 81 ms 16500 KB Output is correct