QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#701629#9529. Farm ManagementMagical_Kingdom#RE 0ms3648kbC++171.4kb2024-11-02 14:27:382024-11-02 14:27:39

Judging History

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

  • [2024-11-02 14:27:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3648kb
  • [2024-11-02 14:27:38]
  • 提交

answer

#include <algorithm>
#include <iostream>
using namespace std;
struct zz {
    long long l, r, w;
} zw[100050];
int cmp(zz a, zz b) {
    return a.w < b.w;
}
int main() {
    long long n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> zw[i].w >> zw[i].l >> zw[i].r;
    }
    long long ans = 0;
    sort(zw + 1, zw + 1 + n, cmp);
    long long tt = m;
    for (int i = 1; i < n; i++) {
        tt -= zw[i].l;
        ans += zw[i].w * zw[i].l;
    }
    long long zc = ans + zw[n].w * zw[n].l;
    long long zg = 0;
    zg = tt - zw[n].l;
    ans += zw[n].w * tt;

    int i = 1, j = n;
    long long sy = zw[j].l;
    long long ans2 = 0;
    while (i < j) {
        zg += zw[i].l;
        zc -= zw[i].l * zw[i].w;
        while (i <= j && zg > 0) {
            if (zg >= zw[j].r - sy) {
                zg -= zw[j].r - sy;
                zc += (zw[j].r - sy) * zw[j].w;
                j--;
                sy = zw[j].l;
                ans2 = max(ans2, zc);
            } else {
                zc += zg * zw[j].w;
                sy += zg;
                zg = 0;
                ans2 = max(ans2, zc);
            }
        }
        zg -= zw[i].l;
        zc += zw[i].l * zw[i].w;
        int ff = i + 1;
        while (zw[ff].l < zw[i].l)
            ff++;
        i = ff;
    }
    cout << max(ans, ans2);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Runtime Error

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:


result: