Submission #1062477

#TimeUsernameProblemLanguageResultExecution timeMemory
1062477zh_hSnail (NOI18_snail)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h>
#define lint long long
#define pb push_back
#define mp make_pair
using namespace std;
lint MOD = 1e9 + 7;
int INF = 1e9;



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

    lint h, p;
    cin >> h >> p;
    vector<lint> v;
    lint sum = 0;
    for(int i = 0; i < p; i ++){
        lint temp;
        cin >> temp;
        v.pb(temp);
        sum += temp;
    }

    if(sum < 0){cout << -1 << " " << -1;}
    else if(sum == 0){
        lint h1 = 0;
        int is_valid = -1;
        for(int i = 0; i < p; i ++){
            if(h1 >= h){is_valid = i; break;}
            h1+=v[i];
            if(h1 < 0){h1 = 0;}
        }
        if(is_valid != -1){cout << 0 << " " << is_valid;}
        else cout << -1 << " " << -1;
    }
    else{
        lint m = 0;
        lint temp = 0;
        for(int i = 0; i < p; i ++){
            temp += v[i];
            m = max(m, temp);
        }

        int days = (h-m+sum-1)/sum;
        int thatday = days*sum;
        int valid;
        if(thatday >= h){
            thatday-=sum;
            days--;
        }
        
        for(int i = 0; i < p; i ++){
            thatday += v[i];
            if(thatday >= h){valid = i; break;}
        }
        cout << days << " " << valid;
        
    }

    return 0;
}

Compilation message (stderr)

snail.cpp: In function 'int main()':
snail.cpp:58:32: warning: 'valid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |         cout << days << " " << valid;
      |                                ^~~~~
#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...