QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678931#9529. Farm Managementucup-team5226#WA 0ms3760kbC++202.5kb2024-10-26 16:26:522024-10-26 16:26:53

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 16:26:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3760kb
  • [2024-10-26 16:26:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
void solve() {
    ll n, m;
    cin >> n >> m;
    struct Item {
        ll w, l, r;
    };
    vector<Item> v;
    rep(i, n) {
        ll w, l, r;
        cin >> w >> l >> r;
        v.emplace_back(w, l, r);
    }
    auto comp = [&](Item& a, Item& b) -> bool {
        if (a.w == b.w) {
            if (a.l == b.l) return a.r > b.r;
            return a.l > b.l;
        }
        return a.w > b.w;
    };
    sort(v.begin(), v.end(), comp);
    ll res = 0, rem = m;
    for (auto [w, l, r] : v) {
        rem -= l;
        res += w * l;
    }
    vector<ll> p(n);
    rep(i, n) p[i] = v[i].l;
    rep(i, n) {
        auto [w, l, r] = v[i];
        ll d = min(rem, r - l);
        res += w * d;
        rem -= d;
        p[i] += d;
    }
    vector<ll> suml0, suml1, sumr0, sumr1;
    rep(i, n) {
        auto [w, l, r] = v[i];
        ll d = r - p[i];
        if (i == 0)
            sumr0.push_back(d), sumr1.push_back(w * d);
        else
            sumr0.push_back(sumr0.back() + d), sumr1.push_back(sumr1.back() + w * d);
    }
    for (int i = n - 1; i >= 0; i--) {
        auto [w, l, r] = v[i];
        ll d = p[i] - l;
        if (i == n - 1)
            suml0.push_back(d), suml1.push_back(w * d);
        else
            suml0.push_back(suml0.back() + 1), suml1.push_back(suml1.back() + w * d);
    }
    ll base = res;
    rep(i, n) {
        ll val = 0, rem = p[i];
        ll idx = lower_bound(sumr0.begin(), sumr0.end(), rem) - sumr0.begin();
        idx = min(idx, i - 1);
        if (idx < 0) continue;
        if (idx) val += sumr1[idx - 1], rem -= sumr0[idx - 1];
        val += v[idx].w * min(rem, v[idx].r - p[idx]);
        rem -= min(rem, v[idx].r - p[idx]);
        val -= (p[i] - rem) * v[i].w;
        res = max(res, base + val);
    }
    reverse(v.begin(), v.end());
    reverse(p.begin(), p.end());
    rep(i, n) {
        ll val = 0, rem = m - p[i];
        ll idx = lower_bound(suml0.begin(), suml0.end(), rem) - suml0.begin();
        idx = min(idx, i - 1);
        if (idx < 0) continue;
        if (idx) val -= suml1[idx - 1], rem -= suml0[idx - 1];
        val -= v[idx].w * min(rem, p[idx] - v[idx].l);
        rem -= min(rem, p[idx] - v[idx].l);
        val += (m - p[i] - rem) * v[i].w;
        res = max(res, base + val);
    }
    cout << res << endl;
}
int main() {
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3568kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

39811391

result:

wrong answer 1st lines differ - expected: '35204500', found: '39811391'