QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707031#9529. Farm Managementwarner1129#WA 0ms3608kbC++202.3kb2024-11-03 14:26:232024-11-03 14:26:25

Judging History

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

  • [2024-11-03 14:26:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-11-03 14:26:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()

bool chmin(auto &a, auto b) { return (b < a) and (a = b, true); }
bool chmax(auto &a, auto b) { return (a < b) and (a = b, true); }

using i64 = long long;

constexpr i64 inf = 1E18;

void solve() {
    int n;
    i64 m;
    cin >> n >> m;

    vector<array<i64, 3>> A(n);
    for (auto &[a, l, r] : A) {
        cin >> a >> l >> r;
    }

    sort(all(A));

    auto ans = [&]() -> i64 {
        i64 rem = m;
        i64 ans = 0;
        for (int i = 0; i < n; i++) {
            auto [a, l, r] = A[i];
            if (i == n - 1) {
                l = 0, r = inf;
            }
            ans += l * a;
            rem -= l;
        }
        for (int i = n - 1; i >= 0; i--) {
            auto [a, l, r] = A[i];
            if (i == n - 1) {
                l = 0, r = inf;
            }
            i64 t = min(rem, r - l);
            ans += t * a;
            rem -= t;
        }
        return ans;
    }();

    i64 cur = 0;
    i64 rem = m;
    vector<i64> use(n);
    for (int i = 0; i < n; i++) {
        auto [a, l, r] = A[i];
        use[i] = l;
        cur += a * use[i];
        rem -= use[i];
    }

    vector<i64> val;
    vector<pair<i64, i64>> pres{{0, 0}};
    for (int i = n - 1; i >= 0; i--) {
        auto [a, l, r] = A[i];

        if (val.size()) {
            i64 k = min(l, pres.back().ff);
            i64 ns = cur - k * a;
            auto it = --lower_bound(all(pres), pair<i64, i64>{k + 1, -1});
            // cerr << "idx = " << it - pres.begin() << " siz = " << pres.size() << '\n';
            // cerr << " val siz = " << val.size() << '\n';
            ns += it->ss;
            if (it->ff - k > 0) {
                ns += (it->ff - k) * val[it - pres.begin()];
            }
            chmax(ans, ns);
        }

        i64 t = min(rem, r - use[i]);
        rem -= t;
        cur += t * a;
        use[i] += t;

        if (use[i] < r) {
            val.push_back(a);
            auto x = pres.back();
            x.ff += r - use[i];
            x.ss += (r - use[i]) * a;
            pres.push_back(x);
        }
    }

    cout << ans << '\n';
}


signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3592kb

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:

34859047

result:

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