1 条题解

  • 0
    @ 2023-9-30 13:32:18

    暴力解决

    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int N = 300005;
    typedef long long ll;
    ll f[N],t[N],c[N];
    int q[N];
    int main(){
        int n,s;
        scanf("%d%d",&n,&s);
        for(int i = 1;i <= n;i++){
            scanf("%lld%lld",&t[i],&c[i]);
            t[i] += t[i-1],c[i] += c[i-1];
        }
        int hh = 0,tt = 0;
        for(int i = 1;i <= n;i++){
            int l = hh,r = tt;
            while(l < r){
                int mid = l + r >> 1;
                if(f[q[mid+1]]-f[q[mid]]<=(t[i]+s)*(c[q[mid+1]]-c[q[mid]]))     l = mid + 1;
                else    r = mid;
            }
            f[i] = f[q[l]] - (t[i] + s) * c[q[l]] + c[i] * t[i] + s * c[n];
            while(hh < tt && (f[q[tt]]-f[q[tt - 1]])*(c[i]-c[q[tt]]) >= (f[i]-f[q[tt]])*(c[q[tt]]-c[q[tt - 1]]))    tt--;
            q[++tt] = i;
        }
        printf("%lld\n",f[n]);
        return 0;
    }
    
    • 1

    信息

    ID
    213
    时间
    1000ms
    内存
    128MiB
    难度
    8
    标签
    递交数
    13
    已通过
    8
    上传者