QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800800#9529. Farm Managementlwj1239WA 1ms7680kbC++111.6kb2024-12-06 15:45:562024-12-06 15:45:58

Judging History

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

  • [2024-12-06 15:45:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7680kb
  • [2024-12-06 15:45:56]
  • 提交

answer

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

using namespace std;

const int N = 1e6 + 10;

struct node {
    int w;
    int l;
    int r;
}a[N];

int sum[N];
int cnt[N];
int n;
int m;

int get(int x, int r) {
    int l = 1;
    int ans = 0;

    while (l <= r) {
        int mid = (l + r) / 2;

        if (cnt[mid] <= x) {
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }

    return ans;
}

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

    for (int i = 1; i <= n; i++) {
        cin >> a[i].w >> a[i].l >> a[i].r;
    }

    sort(a + 1, a + 1 + n, [](node x, node y) {
        return x.w > y.w;
    });

    int tot = 0, res = 0;

    for (int i = 1; i <= n; i++) {
        tot += a[i].w * a[i].l;
        m -= a[i].l;
        sum[i] = (a[i].r - a[i].l) * a[i].w;
        cnt[i] = a[i].r - a[i].l;
    }

    for (int i = 2; i <= n; i++) {
        sum[i] += sum[i - 1];
        cnt[i] += cnt[i - 1];
    }

    for (int i = 1; i <= n; i++) {
        int cur = m + a[i].l;
        int p = get(cur, i - 1);//因为是完全不种植第i种植物,所以我们只能看第i种前面的,因为后面的一定不优
        cur -= cnt[p];
        int t = tot - a[i].l * a[i].w + sum[p];
        int j = i + 1;
        while (j <= n && cur) {
            t += min(cur, a[j].r - a[j].l) * a[j].w;
            cur -= min(cur, a[j].r - a[j].l);
            j  ++;
        }
        // cout << "p = " << p << ' ' << "cur = " << cur << " " << "t = " << t << endl;
        res = max(res, t);
    }
 
    cout << res << endl;
}

signed main() {
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 7680kb

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'