QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695085#9529. Farm Managementdreamwave#WA 0ms3548kbC++141.6kb2024-10-31 19:17:582024-10-31 19:17:59

Judging History

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

  • [2024-10-31 19:17:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-10-31 19:17:58]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using i64 = long long;

struct node {
    int w, l, r;
} ;

void solve() {
    int n;
    i64 m;
    std::cin >> n >> m;
    std::vector < node > a(n);
    for(int i = 0; i < n; ++i) std::cin >> a[i].w >> a[i].l >> a[i].r;
    std::sort(a.begin(), a.end(), [&](const node &x, const node &y) {
        return x.w > y.w;
    });
    i64 ans = 0, re = 0;
    for(int i = 0; i < n; ++i) {
        re += 1LL * a[i].l * a[i].w;
        m -= a[i].l;
    }
    auto cb = re;
    std::vector < i64 > sum(n + 1), add(n + 1);
    for(int i = 0; i < n; ++i) {
        sum[i + 1] = sum[i] + (a[i].r - a[i].l);
        add[i + 1] = add[i] + 1LL * a[i].w * (a[i].r - a[i].l);
    }
    i64 M = m;
    for(int i = 0; i < n; ++i) {
        cb -= 1LL * a[i].l * a[i].w;
        m += a[i].l;
        int l = 0, r = i, to = 0;
        while(l <= r) {
            int mid = (l + r) >> 1;
            if(sum[i] <= m) {
                l = mid + 1;
                to = mid;
            } else {
                r = mid - 1;
            }
        }
        // std::cout << m << ' ' << i << ' ' << a[i].w << ' ' << to << '\n';
        ans = std::max(ans, cb + add[to] + 1LL * (m - sum[to]) * a[to].w);
        ans = std::max(ans, re + 1LL * M * a[i].w);
        i64 cnt = std::min(1LL * (a[i].r - a[i].l), M);
        M -= cnt;
        re += 1LL * cnt * a[i].w;
        cb += 1LL * a[i].l * a[i].w;
        m -= a[i].l;
    }
    std::cout << ans << '\n';
}

signed main() {
    std::cin.tie(nullptr) -> sync_with_stdio(false);
    int T = 1;
    // std::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: 3496kb

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

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:

35277263

result:

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