Submission #1278698

#TimeUsernameProblemLanguageResultExecution timeMemory
1278698jackofall718Snail (NOI18_snail)C++20
37 / 100
2 ms580 KiB
#include <bits/stdc++.h>
#include <chrono>
#define ll long long int
#define endl '\n'
#define vn vector<ll>
#define vi vector<pair <ll,ll>>

using namespace std;
using namespace std::chrono;
const int MAX_N = 1e9 + 7;
#define pii pair<ll,ll>
const ll INF = 0x3f3f3f3f3f3f3f3f;

#define pb push_back  
#define srt(vp) sort(vp.begin(), vp.end()) 

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

    auto start = high_resolution_clock::now();

    ll h,n;
    cin>>h>>n;
    vn v(n);
    for (auto &x:v)cin>>x;
    vn pos(n);
    pos[0]=max(0LL,0+v[0]);
    ll max_h = pos[0];
    for (int i=1;i<n;i++){
        pos[i]=max(0LL,pos[i-1]+v[i]);
        max_h=max(max_h,pos[i]);
    }

    ll daily_gain = 0;
    for (auto &x:v) daily_gain += x;

    // check if snail never escapes
    if (daily_gain <= 0 && max_h < h) {
        cout<<-1<<" "<<-1<<endl;
    }
    else {
        // check within first day
        if (max_h >= h) {
            ll curr = 0;
            for (int i=0;i<n;i++){
                curr = max(0LL, curr + v[i]);
                if (curr >= h) {
                    cout<<0<<" "<<i<<endl;
                    return 0;
                }
            }
        }
        else {
            // compute how many full days needed
            ll rem = h - max_h;
            ll days = rem / daily_gain;
            if (rem % daily_gain) days++;
            ll curr = days * daily_gain;
            
            for (int i=0;i<n;i++){
                curr = max(0LL, curr + v[i]);
                if (curr >= h) {
                    cout<<days<<" "<<i<<endl;
                    return 0;
                }
            }
        }
    }

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    //cout << "Time taken by function: " << duration.count() << " microseconds" << endl;

    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...