Submission #1248600

#TimeUsernameProblemLanguageResultExecution timeMemory
1248600jourSnail (NOI18_snail)C++20
37 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    ll H; 
    int N;
    cin >> H >> N;
    vector<ll> P(N);
    for(int i = 0; i < N; i++) 
        cin >> P[i];

    // 1) Ngày 0: tính dồn từng pha, kiểm tra ngay
    ll sum = 0, maxPref = LLONG_MIN;
    for(int i = 0; i < N; i++){
        sum += P[i];
        if(sum >= H){
            cout << 0 << " " << i;
            return 0;
        }
        maxPref = max(maxPref, sum);
    }

    // 2) Nếu mỗi ngày không tiến lên được nữa -> vô hạn
    if(sum <= 0){
        cout << "-1 -1";
        return 0;
    }

    // 3) Tính số ngày cả ngày cần nhảy vọt
    //    d = ceil((H - maxPref) / sum)
    ll need = H - maxPref;
    ll d = (need + sum - 1) / sum;

    // 4) Lần chạy ngày thứ d: từ đầu pha 0
    ll cur = d * sum;
    for(int i = 0; i < N; i++){
        cur += P[i];
        if(cur >= H){
            cout << d << " " << i;
            return 0;
        }
    }

    // logic chắc chắn đã trả về bên trên
    cout << "-1 -1";
    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...