Elevator

Elevator

线性规划

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpi = tuple<int, int, int>;

void solve() {
    int n; cin >> n;
    ll k; cin >> k;
    map<int, ll> mp;
    for(int i = 1; i <= n; i ++) {
        ll c, w; int f; cin >> c >> w >> f;
        mp[f] += c * w;
    }

    ll pre = 0, tol = 0;
    ll ans = 0;
    for(auto it = mp.rbegin(); it != mp.rend(); it ++) {
        int f = it->first;
        ll w = it->second;

        tol += w;
        ll cur = (tol + k - 1) / k;
        // tol为总量,如果出现能跟随上一组一起上去,也就会考虑进去
        // 这是基于w = 1/2  k为偶数的性质

        ans += (cur - pre) * f;
        pre = cur;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int _ = 1; cin >> _;
    while(_--) solve();
    return 0;
}
posted @ 2026-11-03 21:47  thenrify  阅读(3)  评论(0)    收藏  举报