#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
long long H;
int N;
cin >> H >> N;
vector<long long> P(N), pref(N);
for(int i = 0; i < N; i++){
cin >> P[i];
if(i == 0) pref[i] = P[i];
else pref[i] = pref[i-1] + P[i];
}
// 1) Ki?m tra ngay trong ngày d?u (day = 0)
for(int j = 0; j < N; j++){
if(pref[j] >= H){
cout << 0 << " " << j << "\n";
return 0;
}
}
long long S = pref[N-1]; // t?ng m?i ngày
if(S <= 0){
// không ti?n lên du?c
cout << "-1 -1\n";
return 0;
}
// 2) Tính s? ngày toàn ph?n c?n lùi (day >= 1)
long long maxPref = *max_element(pref.begin(), pref.end());
long long need = H - maxPref;
// ceil(need / S)
long long d = (need + S - 1) / S;
// 3) Tìm pha d?u tiên trong ngày d mà >= H
for(int j = 0; j < N; j++){
long long height = d * S + pref[j];
if(height >= H){
cout << d << " " << j << "\n";
return 0;
}
}
// Không bao gi? x?y ra v?i logic dúng
cout << "-1 -1\n";
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... |