Submission #1322288

#TimeUsernameProblemLanguageResultExecution timeMemory
1322288rycSnail (NOI18_snail)C++20
0 / 100
1095 ms856 KiB
#include <bits/stdc++.h>
using namespace std;

long long findHighestPoint(const vector<long long>& p) {
    long long cpoint = 0;
    long long hpoint = 0;

    // Create newlist = p * 2
    vector<long long> newlist = p;
    newlist.insert(newlist.end(), p.begin(), p.end());

    for (long long x : newlist) {
        cpoint += x;
        if (cpoint < 0) cpoint = 0;
        if (cpoint > hpoint) hpoint = cpoint;
    }

    return hpoint;
}

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

    long long h;
    int n;
    cin >> h >> n;

    vector<long long> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    vector<long long> ans = {0, -1};

    long long SumPhases = accumulate(p.begin(), p.end(), 0LL);

    if (SumPhases <= 0 && h - findHighestPoint(p) > 0) {
        cout << "-1 -1\n";
        return 0;
    }

    bool notDone = true;

    while (notDone) {

        if (h - findHighestPoint(p) <= 0) {

            // checkarr = p * 2
            vector<long long> checkarr = p;
            checkarr.insert(checkarr.end(), p.begin(), p.end());

            ans[1] = -1;

            for (int i = 0; i < (int)checkarr.size(); i++) {
                h -= checkarr[i];
                ans[1]++;

                if (h <= 0) {
                    notDone = false;

                    if (i <= n - 1) {
                        cout << ans[0] << " " << ans[1] << "\n";
                    } else {
                        ans[0]++;
                        ans[1] -= n;
                        cout << ans[0] << " " << ans[1] << "\n";
                    }
                    break;
                }
            }

        } else {
            h -= SumPhases;
            ans[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...