답안 #935078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935078 2024-02-28T15:05:28 Z haxorman Snowball (JOI21_ho_t2) C++14
0 / 100
2 ms 2652 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 2e5 + 7;

int arr[mxN], ans[mxN];

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n, q;
    cin >> n >> q;
    
    vector<pair<int,int>> dist;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];

        if (i && abs(arr[i] - arr[i-1])) {
            dist.push_back({abs(arr[i] - arr[i-1]), i-1});
        }
    }
    sort(dist.begin(), dist.end(), greater<pair<int,int>>());

    int l = 0, r = 0, cur = 0;
    for (int i = 0; i < q; ++i) {
        int w;
        cin >> w;

        cur += w;
        l = min(l, cur);
        r = max(r, cur);
    
        while (dist.size() && abs(l) + r >= dist.back().first) {
            auto [d, id] = dist.back();
            dist.pop_back();
            
            //cout << d << ' ' << id << ' ' << l << ' ' << r << ' ' << w << '\n';

            if (w>=0) {
                ans[id] += d-abs(l);
                ans[id+1] += abs(l);
            }
            else {
                ans[id+1] += d-r;
                ans[id] += r;
            }
        }
    }
    
    ans[0] += abs(l), ans[n-1] += r;
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << "\n";
    }
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:36:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |             auto [d, id] = dist.back();
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2548 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Incorrect 1 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2548 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Incorrect 1 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -