QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715033#9529. Farm Managementljljljlj#WA 0ms3612kbC++202.0kb2024-11-06 10:02:332024-11-06 10:02:35

Judging History

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

  • [2024-11-06 10:02:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-06 10:02:33]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
using i64 = long long;
const int inf = 1e18;
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> a(n + 1);
    for (int i = 1, w, l, r; i <= n; i++)
    {
        cin >> w >> l >> r;
        a[i] = make_tuple(w, l, r);
    }
    sort(a.begin() + 1, a.end(), [](auto &x, auto &y)
         { return get<0>(x) != get<0>(y) ? get<0>(x) > get<0>(y) : get<2>(x) > get<2>(y); });
    vector<int> pre(n + 1), suf(n + 2);
    vector<int> presum(n + 1), sufsum(n + 2);
    for (int i = 1; i <= n; i++)
    {
        pre[i] = pre[i - 1] + get<2>(a[i]);
        presum[i] += presum[i - 1] + get<0>(a[i]) * get<2>(a[i]);
    }
    for (int i = n; i >= 1; i--)
    {
        suf[i] = suf[i + 1] + get<1>(a[i]);
        sufsum[i] = sufsum[i + 1] + get<0>(a[i]) * get<1>(a[i]);
    }
    int mx = 0;
    for (int i = 1; i <= n; i++)
    {
        if (pre[i - 1] + suf[i + 1] > m)
        {
            int L = 1, R = i - 1, ans = -1;
            auto check = [&](int mid) -> bool
            {
                int res = pre[mid] + suf[mid + 1] - get<1>(a[i]);
                return res <= m;
            };
            while (L <= R)
            {
                int mid = L + R >> 1;
                if (check(mid))
                    ans = mid, L = mid + 1;
                else
                    R = mid - 1;
            }
            int res = 0;
            res = sufsum[ans + 1] - get<0>(a[i]) * get<1>(a[i]) + presum[ans] + (m - pre[ans] - suf[ans + 1]) * get<0>(a[ans + 1]);
            mx = max(mx, res);
        }
        else
            mx = max(mx, presum[i - 1] + sufsum[i + 1] + (m - pre[i - 1] - suf[i + 1]) * get<0>(a[i]));
    }
    cout << mx << endl;
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    // system("pause");
    return 0;
}

詳細信息

Test #1:

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

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

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:

32281150

result:

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