为啥题解里都是二分,不可以直接按照循环节求解?
查看原帖
为啥题解里都是二分,不可以直接按照循环节求解?
549027
__JiCanDuck__楼主2023/6/13 14:59

写完后#5WA,不知咋的,CF看不到数据...求hack

#include <iostream>

using namespace std;
using ll = long long;

const int kMaxN = 2e5 + 5;

ll h, n, a[kMaxN], l, t;

int main() {
  cin >> h >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    l -= a[i];
  }
  if (l <= 0) {
    return cout << -1, 0;
  }
  t = (h / l - 1) * n - 1;
  h = h % l + l;
  for (int i = 0; i <= n; i++) {
    h += a[i];
    if (h <= 0) {
      return cout << ++t, 0;
    }
    t++;
  }
  return 0;
}
2023/6/13 14:59
加载中...