# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1060392 | 2024-08-15T13:39:36 Z | khanhtb | Just Long Neckties (JOI20_ho_t1) | C++14 | 195 ms | 21844 KB |
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<ll> #define vii vector<vi> #define pll pair<ll, ll> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; const ll mod = 1e9+7; const ll inf = 2e18; const ll B = 320; const ll N = 2e5+8; ll n,b[N],ans[N]; pair<ll,ll> a[N]; void solve(){ cin >> n; multiset<ll> s; for(ll i = 1; i <= n+1; i++) cin >> a[i].fi, a[i].se = i; for(ll i = 1; i <= n; i++) cin >> b[i]; sort(a+1,a+n+2),sort(b+1,b+n+1); for(ll i = 1; i <= n; i++){ s.insert(max(a[i+1].fi - b[i],0LL)); } for(ll i = 1; i <= n+1; i++){ ans[a[i].se] = *s.rbegin(); if(i <= n){ s.erase(s.find(max(a[i+1].fi - b[i],0LL))); s.insert(max(a[i].fi - b[i],0LL)); } } for(ll i = 1; i <= n+1; i++) cout << ans[i] << " "; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll T = 1; // cin >> T; for (ll i = 1; i <= T; i++) { solve(); cout << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Correct | 0 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 0 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 0 ms | 2396 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 0 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Correct | 0 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 0 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 0 ms | 2396 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 0 ms | 2396 KB | Output is correct |
13 | Correct | 1 ms | 2396 KB | Output is correct |
14 | Correct | 1 ms | 2524 KB | Output is correct |
15 | Correct | 1 ms | 2652 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 1 ms | 2652 KB | Output is correct |
18 | Correct | 1 ms | 2652 KB | Output is correct |
19 | Correct | 1 ms | 2684 KB | Output is correct |
20 | Correct | 1 ms | 2652 KB | Output is correct |
21 | Correct | 1 ms | 2652 KB | Output is correct |
22 | Correct | 1 ms | 2524 KB | Output is correct |
23 | Correct | 1 ms | 2528 KB | Output is correct |
24 | Correct | 2 ms | 2648 KB | Output is correct |
25 | Correct | 2 ms | 2652 KB | Output is correct |
26 | Correct | 1 ms | 2652 KB | Output is correct |
27 | Correct | 2 ms | 2648 KB | Output is correct |
28 | Correct | 2 ms | 2652 KB | Output is correct |
29 | Correct | 1 ms | 2652 KB | Output is correct |
30 | Correct | 1 ms | 2676 KB | Output is correct |
31 | Correct | 1 ms | 2652 KB | Output is correct |
32 | Correct | 1 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 0 ms | 2396 KB | Output is correct |
4 | Correct | 0 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 0 ms | 2396 KB | Output is correct |
8 | Correct | 0 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 0 ms | 2396 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 0 ms | 2396 KB | Output is correct |
13 | Correct | 1 ms | 2396 KB | Output is correct |
14 | Correct | 1 ms | 2524 KB | Output is correct |
15 | Correct | 1 ms | 2652 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 1 ms | 2652 KB | Output is correct |
18 | Correct | 1 ms | 2652 KB | Output is correct |
19 | Correct | 1 ms | 2684 KB | Output is correct |
20 | Correct | 1 ms | 2652 KB | Output is correct |
21 | Correct | 1 ms | 2652 KB | Output is correct |
22 | Correct | 1 ms | 2524 KB | Output is correct |
23 | Correct | 1 ms | 2528 KB | Output is correct |
24 | Correct | 2 ms | 2648 KB | Output is correct |
25 | Correct | 2 ms | 2652 KB | Output is correct |
26 | Correct | 1 ms | 2652 KB | Output is correct |
27 | Correct | 2 ms | 2648 KB | Output is correct |
28 | Correct | 2 ms | 2652 KB | Output is correct |
29 | Correct | 1 ms | 2652 KB | Output is correct |
30 | Correct | 1 ms | 2676 KB | Output is correct |
31 | Correct | 1 ms | 2652 KB | Output is correct |
32 | Correct | 1 ms | 2652 KB | Output is correct |
33 | Correct | 131 ms | 20600 KB | Output is correct |
34 | Correct | 166 ms | 21332 KB | Output is correct |
35 | Correct | 125 ms | 20684 KB | Output is correct |
36 | Correct | 135 ms | 21332 KB | Output is correct |
37 | Correct | 139 ms | 21736 KB | Output is correct |
38 | Correct | 131 ms | 21844 KB | Output is correct |
39 | Correct | 178 ms | 20560 KB | Output is correct |
40 | Correct | 177 ms | 20560 KB | Output is correct |
41 | Correct | 179 ms | 20564 KB | Output is correct |
42 | Correct | 184 ms | 20572 KB | Output is correct |
43 | Correct | 177 ms | 20596 KB | Output is correct |
44 | Correct | 114 ms | 19860 KB | Output is correct |
45 | Correct | 114 ms | 20052 KB | Output is correct |
46 | Correct | 112 ms | 20056 KB | Output is correct |
47 | Correct | 110 ms | 20460 KB | Output is correct |
48 | Correct | 121 ms | 20364 KB | Output is correct |
49 | Correct | 184 ms | 21072 KB | Output is correct |
50 | Correct | 195 ms | 21076 KB | Output is correct |
51 | Correct | 184 ms | 20912 KB | Output is correct |
52 | Correct | 178 ms | 20964 KB | Output is correct |
53 | Correct | 184 ms | 21072 KB | Output is correct |