QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728107#9529. Farm Managementpugong#WA 0ms3556kbC++202.2kb2024-11-09 14:34:532024-11-09 14:34:54

Judging History

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

  • [2024-11-09 14:34:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3556kb
  • [2024-11-09 14:34:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 

struct Node {
    int w, l, r;
    int s1;
};
struct node {
    int sum, cnt;
    int pos;
};
void solve() {
    int n, m;cin >> n >> m;
    vector<Node>a(n + 1);
    for (int i = 1;i <= n;i++) {
        cin >> a[i].w >> a[i].l >> a[i].r;
        a[i].s1 = a[i].w * a[i].l;
    }
    sort(a.begin() + 1, a.end(), [&](auto l, auto r) {
        return l.w < r.w;
         });
    vector<int>pre(n + 10, 0), suf(n + 10, 0);
    vector<int>presum(n + 10, 0), sufsum(n + 10, 0);
    for (int i = 1;i <= n;i++) {
        pre[i] = pre[i - 1] + a[i].l;
        presum[i] = presum[i - 1] + a[i].l * a[i].w;
    }
    vector<pair<int, int>>oth;
    for (int i = n;i >= 1;i--) {
        if (a[i].r + pre[i - 1] + (suf[i + 1]) <= m) {
            suf[i] = suf[i + 1] + a[i].r;
        }
        else {
            int k = m - pre[i - 1] - suf[i + 1];
            oth.push_back({ a[i].r - k,i });
            suf[i] = suf[i + 1] + k;
        }
        sufsum[i] = sufsum[i + 1] + (suf[i] - suf[i + 1]) * a[i].w;
    }
    vector<node>oth2(oth.size() + 1);
    for (int i = 0;i < oth.size();i++) {
        oth2[i + 1].cnt = oth2[i].cnt + oth[i].first;
        oth2[i + 1].sum = oth2[i].sum + a[oth[i].second].w * oth[i].first;
        oth2[i + 1].pos = oth[i].second;
    }
    sort(oth2.begin() + 1, oth2.end(), [&](auto l, auto r) {
        return l.sum < r.sum;
         });
    int ans = 0;
    for (int i = 1;i <= n;i++) {
        int m1 = presum[i - 1];
        int m2 = sufsum[i + 1];
        int t = m - pre[i - 1] - suf[i + 1];
        int l = 1, r = oth2.size() + 1;
        while (l + 1 != r) {
            int mid = l + r >> 1;
            if (oth2[mid].cnt >= t && oth2[mid].pos >= i) r = mid;
            else l = mid;
        }
        // cout << l << "\n";
        int el = 0;
        if (t - oth2[l].cnt >= 0) el = t - oth2[l].cnt;
        ans = max(ans, m1 + m2 + oth2[l].sum + el * a[i].w);
    }
    cout << ans << "\n";
}

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

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3556kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

100852

result:

wrong answer 1st lines differ - expected: '109', found: '100852'