Submission #1090610

#TimeUsernameProblemLanguageResultExecution timeMemory
1090610dpsaveslivesSnail (NOI18_snail)C++17
0 / 100
1 ms456 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll H,N; cin >> H >> N;
    vector<ll> phases(N); ll day0 = 0, sec = 0;
    for(int i = 0;i<N;++i){
        cin >> phases[i];
        sec += phases[i];
        day0 += phases[i];
        day0 = max(day0,0ll);
    }
    ll cur = 0;
    for(int i = 0;i<2;++i){
        for(int j = 0;j<N;++j){
            cur += phases[j];
            cur = max(cur,0ll);
            if(cur >= H){
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
    if(sec <= 0){
        cout << -1 << " " << -1 << "\n";
    }
    else{
        ll best = 0; cur = 0;
        for(int i = 0;i<N;++i){
            cur += phases[i];
            best = max(best,cur);
        }
        best -= day0;
        ll maxn = (H-best-day0+sec-1)/sec;
        cur = maxn*sec+day0;
        for(int i = 0;i<N;++i){
            cur += phases[i];
            if(cur >= H){
                cout << maxn+1 << " " << i << "\n";
                return 0;
            }
        }
    }
    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...