AcWing 3659. 加油站
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 5e3 + 10;
int t, n, m, k, l, r, op, x, y, cnt;
int f[N];
bool flag;
void solve() {
while (cin >> n >> k) {
x = n, cnt = 0, flag = true;
for (int i = 1; i <= k + 1; i++) {
cin >> f[i];
}
for (int i = 1; i <= k + 1; i++) {
if (x < 0) {
flag = false;
break;
}
if (x - f[i] < 0) {
x = n;
cnt++;
}
x -= f[i];
}
if (x < 0) {
flag = false;
}
if (flag) {
cout << cnt;
} else {
cout << "No Solution";
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}