답안 #1023805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1023805 2024-07-15T06:45:44 Z vjudge1 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
79 ms 15444 KB
#include <iostream>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define ROF(i,m,n) for(int i=m;i<=n;i++)
#define vi vector<int>
#define pb push_back
#define alle(a) a.begin(),a.end()
#define rall(n) rbegin(n),rend(n)
#define int long long
#define vecs vector<int> 
#define ll long long
#define ss second 
#define ff first
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 200005;
int dp1[N], dp2[N],B[N], ans[N];
pair<int,int> A[N];
void solve(){
    int n;
    cin >> n;
    
    for(int i = 1; i <= n + 1; ++i) {
        cin >> A[i].first;
        A[i].second = i;
    }
    for(int i = 1; i <= n; ++i) {
        cin >> B[i];
    }
    sort(B + 1, B + n + 1);
    sort(A + 1, A + n + 2);
    for(int i = 1; i <= n; ++i) {
        dp1[i] = max(dp1[i - 1], A[i].first - B[i]);
    }
    
    for(int i = n + 1; i >= 2; --i) {
        dp2[i] = max(dp2[i + 1], A[i].first - B[i - 1]);
    }

    for(int i = 1; i <= n + 1; ++i) {
        ans[A[i].second] = max(dp1[i - 1], dp2[i + 1]);
    }

    for(int i = 1; i <= n + 1; ++i) {
        cout << ans[i] << ' ';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 476 KB Output is correct
24 Correct 1 ms 532 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 524 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 476 KB Output is correct
24 Correct 1 ms 532 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 524 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 64 ms 13888 KB Output is correct
34 Correct 69 ms 15188 KB Output is correct
35 Correct 65 ms 14676 KB Output is correct
36 Correct 66 ms 15188 KB Output is correct
37 Correct 69 ms 15444 KB Output is correct
38 Correct 67 ms 15444 KB Output is correct
39 Correct 66 ms 14472 KB Output is correct
40 Correct 65 ms 14416 KB Output is correct
41 Correct 67 ms 14424 KB Output is correct
42 Correct 66 ms 14412 KB Output is correct
43 Correct 79 ms 14452 KB Output is correct
44 Correct 64 ms 13908 KB Output is correct
45 Correct 64 ms 13908 KB Output is correct
46 Correct 65 ms 13904 KB Output is correct
47 Correct 66 ms 14160 KB Output is correct
48 Correct 76 ms 14048 KB Output is correct
49 Correct 65 ms 14676 KB Output is correct
50 Correct 66 ms 14672 KB Output is correct
51 Correct 68 ms 14676 KB Output is correct
52 Correct 67 ms 14676 KB Output is correct
53 Correct 67 ms 14692 KB Output is correct