QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#800734#9529. Farm Managementlwj1239WA 1ms7768kbC++111.6kb2024-12-06 15:08:232024-12-06 15:08:26

Judging History

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

  • [2024-12-06 15:08:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7768kb
  • [2024-12-06 15:08:23]
  • 提交

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 l = 1;
    int r = n;
    int ans = 0;

    while (l <= r) {
        int mid = l + (r - l >> 1);

        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];
    }

    //cout << "sum = " << endl;
    //for (int i = 1; i <= n; i++) {
    //    cout << sum[i] << " ";
    //}
    //cout << endl;
    //
    //cout << "cnt = " << endl;
    //for (int i = 1; i <= n; i++) {
    //    cout << cnt[i] << ' ';
    //}
    //cout << endl;

    for (int i = 1; i <= n; i++) {
        int cur = m + a[i].l;
        int p = get(cur);
        //cout << "p = " << p << endl;
        cur -= cnt[p];
        int t = tot - a[i].l * a[i].w + sum[p] + cur * a[p + 1].w;
        res = max(res, t);
    }
 
    cout << res << endl;
}

signed main() {
    solve();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7768kb

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: 0
Accepted
time: 0ms
memory: 7688kb

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:

35204500

result:

ok single line: '35204500'

Test #3:

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

input:

15 32
835418 2 3
178262 1 3
527643 2 2
519710 1 1
774544 3 3
82312 1 1
808199 1 1
809396 1 3
255882 1 3
80467 1 3
874973 1 3
813965 1 2
198275 1 2
152356 1 3
802055 1 1

output:

17015002

result:

wrong answer 1st lines differ - expected: '22000255', found: '17015002'