# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090132 | dpsaveslives | Snail (NOI18_snail) | C++17 | 1 ms | 604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll H; int N; cin >> H >> N;
vector<ll> phases(N);
vector<ll> pref(N);
bool neg = false;
for(int i = 0;i<N;++i){
cin >> phases[i];
if(i == 0){
pref[i] = max(0ll,phases[i]);
if(phases[i] < 0) neg = true;
}
else{
if(phases[i]+pref[i-1] < 0){
neg = true;
}
pref[i] = max(0ll,phases[i]+pref[i-1]);
}
}
/*if(neg){
for(int i = 0;i<N;++i){
if(pref[i] >= H){
cout << 0 << " " << i << "\n";
return 0;
}
}
ll cur = pref[N-1];
for(int i = 0;i<N;++i){
cur += phases[i];
if(cur >= H){
cout << 1 << " " << i << "\n";
return 0;
}
}
cout << -1 << " " << -1 << "\n";
return 0;
}
ll ans = -1, p = -1;
for(int i = 0;i<N;++i){
ll cur = H-pref[i];
if(cur <= 0){
if(ans == -1 || 0 < ans){
ans = 0;
p = i;
}
continue;
}
ll d = cur/pref[N-1];
if(cur % pref[N-1] != 0){
++d;
}
if(ans == -1 || d < ans){
ans = d;
p = i;
}
}
cout << ans << " " << p << "\n";*/
return 0;
}
Compilation message (stderr)
# | 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... |