Submission #1228381

#TimeUsernameProblemLanguageResultExecution timeMemory
1228381surung9898Snail (NOI18_snail)C++20
37 / 100
1 ms328 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
#ifdef _MSC_VER
#	include <intrin.h>
#	define __builtin_popcountll __popcnt
#endif

//#include <atcoder/all>
//using namespace atcoder;
//typedef modint998244353 mint;

using namespace std;

typedef long long int lld;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;
typedef vector<int> vi;
typedef vector<lld> vl;
typedef vector<ld> vld;
typedef vector<char> vch;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vivi;
typedef vector<vl> vlvl;
typedef vector<vch> vcvc;
typedef vector<vb> vbvb;
typedef vector<vs> vsvs;

const lld mod = 1000000000000;
const lld inf = 1LL << 56;
const int nom = 200000;

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

    int n;
    lld h, mx = -inf, diff = 0, fa = -1, fb = -1;

    cin >> h >> n;

    vl vc(n);

    for (int i = 0; i < n; ++i)
        cin >> vc[i];

    for (int i = 0; i < n; ++i)
    {
        diff += vc[i];
        mx = max(mx, diff);
    }

    if (mx >= h)
    {
        fa = 0;
        diff = 0;

        for (int i = 0; i < n; ++i)
        {
            diff += vc[i];

            if (diff >= h)
            {
                fb = i;

                break;
            }
        }

        cout << fa << ' ' << fb;
    }
    else if (diff <= 0)
        cout << -1 << ' ' << -1;
    else
    {
        h -= mx;
        fa = h / diff - 1;
        h = h % diff + mx;

        while (h > 0)
        {
            for (int i = 0; i < n; ++i)
            {
                h -= vc[i];

                if (h <= 0)
                {
                    fb = i;

                    break;
                }
            }

            fa++;
        }

        cout << fa << ' ' << fb;
    }

    cout << '\n';

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