#include <bits/stdc++.h>
#include <chrono>
#define ll long long int
#define endl '\n'
#define vn vector<ll>
using namespace std;
using namespace std::chrono;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll h,n;
cin>>h>>n;
vn v(n);
for (auto &x:v)cin>>x;
// simulate up to 2N phases
ll height = 0;
for (int day=0; day<2; day++) {
for (int i=0; i<n; i++) {
height = max(0LL, height + v[i]);
if (height >= h) {
cout<<day<<" "<<i<<endl;
return 0;
}
}
}
// if not escaped, compute daily gain
ll daily_gain = 0;
for (auto &x:v) daily_gain += x;
if (daily_gain <= 0) {
cout<<-1<<" "<<-1<<endl;
return 0;
}
// prefix heights after each phase in 1 day
vn prefix(n);
ll curr = 0;
for (int i=0;i<n;i++){
curr = max(0LL, curr + v[i]);
prefix[i] = curr;
}
ll best_day = LLONG_MAX;
ll best_phase = -1;
for (int i=0;i<n;i++){
if (prefix[i] >= h) { // already handled, but safe
cout<<0<<" "<<i<<endl;
return 0;
}
ll need = h - prefix[i];
ll day = (need + daily_gain - 1) / daily_gain; // ceil division
if (day < best_day || (day == best_day && i < best_phase)) {
best_day = day;
best_phase = i;
}
}
cout<<best_day<<" "<<best_phase<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |