QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719435#9529. Farm ManagementxggxWA 0ms3776kbC++171.1kb2024-11-07 01:07:172024-11-07 01:07:17

Judging History

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

  • [2024-11-07 01:07:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3776kb
  • [2024-11-07 01:07:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    ll n, m;
    cin >> n >> m;
    vector<array<int, 3>> a(n + 1);
    for (int i = 1; i <= n; i ++) {
        int w, l, r;
        cin >> w >> l >> r;
        a[i] = {w, l, r};
    }

    sort(a.begin() + 1, a.end(), [&](array<int, 3> &x, array<int, 3> &y) -> bool {
        return x[0] > y[0];
    });

    ll tot = 0;
    vector<ll> sum(n + 1), cnt(n + 1);
    for (int i = 1; i <= n; i++) {
        tot += 1ll * a[i][0] * a[i][1];
        m -= a[i][1];
        sum[i] = sum[i - 1]  + 1ll * a[i][0] * (a[i][2] - a[i][1]);
        cnt[i] = cnt[i - 1] + 1ll * (a[i][2] - a[i][1]);
    }

    ll ans = tot;
    for (int i = 1; i <= n; i++) {
        ll cur = m + a[i][1];
        int pos = upper_bound(cnt.begin() + 1, cnt.begin() + i, cur) - cnt.begin() - 1;
        cur -= cnt[pos];
        ll t = tot - 1ll * a[i][0] * a[i][1] + sum[pos] + cur * a[i][0];
        ans = max(t, ans);
    }

    cout << ans;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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'