답안 #624323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624323 2022-08-07T19:46:56 Z Ronin13 Snowball (JOI21_ho_t2) C++14
0 / 100
4 ms 348 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const int NMAX = 200005;
const ll linf = 1e18 + 1;
ll mn[NMAX], mx[NMAX];


int main(){
    int n, q; cin >> n >> q;
    ll a[n + 2];
    a[0] = -linf;
    a[n + 1] = linf;
    for(int i =1; i <= n; i++) cin >> a[i];
    ll pref[q + 1];
    mn[0] = 0;
    mx[0] = 0;
    pref[0] = 0;
    for(int i = 1; i <= q; i++){
        ll x; cin >> x;
        pref[i] = pref[i - 1] + x;
        mx[i] = max(mx[i - 1], pref[i]);
        mn[i] = min(mn[i - 1], pref[i]);
        //cout << mx[i] << ' ' << mn[i] << "\n";
    }
    ll ans[n + 2];
    for(int i = 0; i <= n + 1; i++) ans[i] = 0;
    for(int i = 1; i <= n + 1; i++){
        ll l = 0, r = a[i] - a[i - 1];
        while(l + 1 < r){
            ll mid = (l + r) / 2;
            ll l1 = -1, r1 = q + 1;
            while(l1 + 1 < r1){
                ll mid1 = l1 + r1; mid1 /= 2;
                if(mn[mid1] <= -mid) r1 = mid1;
                else l1 = mid1;
            }
           // cout << 1;

            if(r1 == q + 1){
                r = mid;
                continue;
            }
            if(mx[r1] <= a[i] - a[i - 1] - mid) l = mid;
            else {r = mid;}
        }
        //cout << l << "\n";
        ans[i - 1] += min(mx[q], a[i] - a[i - 1] - l);
        ans[i] += l;
    }
    for(int i = 1; i <= n; i++){
        cout << ans[i] << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 324 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 3 ms 320 KB Output is correct
7 Incorrect 3 ms 324 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 324 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 3 ms 320 KB Output is correct
7 Incorrect 3 ms 324 KB Output isn't correct
8 Halted 0 ms 0 KB -