제출 #1330116

#제출 시각아이디문제언어결과실행 시간메모리
1330116edoSnail (NOI18_snail)C++20
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    ll H;
    cin >> H >> n;
    vector<ll> h(n);
    for(auto &i : h) cin >> i;

    ll curr = 0;
    for(int i = 0; i < n; i++) { 
        curr += h[i];
        curr = max(0ll, curr);
        if(curr >= H) {
            cout << "0 " << i;
            exit(0);
        }
    }

    ll h0 = curr, h1 = h0, S = h0;
    for(int i = 0; i < n; i++) {
        h1 = max(0ll, h1 + h[i]);
        S = max(S, h1);
        if(h1 >= H) {
            cout << "1 " << i;
            exit(0);
        }
    }
    if((h1 - h0) <= 0) {
        cout << "-1 -1"; 
        exit(0);
    }
    pair<ll, int> mn = {1e18, 1e18};
    ll pref = 0;
    for(int i = 0; i < n; i++) {
        pref += h[i];
        ll target = H - h0 - pref;
        ll d_neg;
        if(target <= 0) 
            d_neg = 0;
        else 
            d_neg = (target + S - 1) / S;

        curr = d_neg + 1;
        mn = min(mn, {curr, i});
    }
    cout << mn.first << " " << mn.second;
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...