• 2018 Multi-University Training Contest 8


    贪心 + 模拟

    预处理出最便宜的原材料价格,然后用map储存每种价格的电脑数量。

    这里因为每个月价格都在变化,所以可以用相对价格,也就是减去一个sigema(e[i])。

    每次选择最小的卖,统计贡献,最后如果超出库存,反着删除即可(相当于没有生产这些电脑)

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    using namespace std;
    typedef long long ll;
    inline int lowbit(int x){ return x & (-x); }
    inline ll read(){
        ll ret = 0, w = 0; char ch = 0;
        while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
        while(isdigit(ch)) ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = getchar();
        return w ? -ret : ret;
    }
    inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
    inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
    template <typename T>
    inline T max(T x, T y, T z){ return max(max(x, y), z); }
    template <typename T>
    inline T min(T x, T y, T z){ return min(min(x, y), z); }
    template <typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    
    const int N = 50005;
    ll _, k, c[N], d[N], m[N], p[N], e[N], R[N], E[N];
    map<ll, ll> record;
    int main(){
    
        for(_ = read(); _; _ --){
            k = read(), record.clear();
            for(int i = 1; i <= k; i ++){
                c[i] = read(), d[i] = read(), m[i] = read(), p[i] = read();
            }
            for(int i = 1; i < k; i ++){
                e[i] = read(), R[i] = read(), E[i] = read();
            }
            for(int i = 1; i < k; i ++){
                if(c[i] + R[i] < c[i + 1]) c[i + 1] = c[i] + R[i];
            }
            ll ans = 0;
            int sum = 0, tot = 0;
            for(int i = 1; i <= k; i ++){
                record[c[i] + m[i] - sum] += p[i], tot += p[i];
                while(!record.empty() && d[i]){
                    if(record.begin()->second > d[i]){
                        tot -= d[i];
                        record.begin()->second -= d[i];
                        ans += (record.begin()->first + sum) * d[i];
                        d[i] = 0;
                    }
                    else{
                        tot -= record.begin()->second;
                        d[i] -= record.begin()->second;
                        ans += (record.begin()->first + sum) * record.begin()->second;
                        record.erase(record.begin()->first);
                    }
                }
                if(d[i]){
                    ans = -1;
                    break;
                }
                if(tot > e[i]){
                    while(!record.empty() && tot > e[i]){
                        if(tot - record.rbegin()->second >= e[i]){
                            tot -= record.rbegin()->second;
                            record.erase(record.rbegin()->first);
                        }
                        else{
                            record.rbegin()->second -= (tot - e[i]);
                            tot = e[i];
                        }
                    }
                }
                sum += E[i];
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    帐户当前被锁定,所以用户 sa 登录失败。系统管理员无法将该帐户解锁 解决方法
    Web页中table导出到execl(带模板)
    Jquery选择器
    JS 用window.open()函数,父级页面如何取到子级页面的返回值?
    SQL2008:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。
    划线标注
    Unity与Android间的交互
    ActiveMQ的配置与使用
    OpenCv的Java,C++开发环境配置
    JDBC的超时原理
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/11164373.html
Copyright © 2020-2023  润新知