|
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- typedef long long LL;
- const int N = 1010;
- const LL INF = 1ll << 62;
- using namespace std;
- LL L, W, n, w[N], sum[N];
- double t[N], v[N], f[N], ST[N][60];
- void STinit() {
- for(int j = 1; j <= 59; j++) {
- for(int i = 1; i + (1ll << j) - 1 <= n; i++) {
- ST[i][j] = max(ST[i][j - 1], ST[i + (1ll << (j - 1))][j - 1]);
- }
- }
- return;
- }
- inline double getmax(int l, int r) {
- int k = 0;
- for(int i = 0; i <= 59 && ((1ll << i) <= (r - l + 1)); i++) {
- k = i;
- }
- return max(ST[l][k], ST[r - (1ll << k) + 1][k]);
- }
- int main() {
- scanf("%lld%lld%lld", &W, &L, &n);
- for(int i = 1; i <= n; i++) {
- scanf("%lld%lf", &w[i], &v[i]);
- t[i] = ((double)L / v[i]) * 60;
- ST[i][0] = t[i];
- sum[i] = sum[i - 1] + w[i];
- }
- STinit();
- f[1] = t[1];
- for(int i = 2; i <= n; i++) {
- f[i] = (double)(INF);
- for(int j = 1; i - j >= 0 && sum[i] - sum[i - j] <= W; j++) { /// i - j | i - j + 1
- f[i] = min(f[i], f[i - j] + getmax(i - j + 1, i));
- }
- }
- printf("%.1lf", f[n]);
- return 0;
- }
复制代码 |
|