QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728898#9529. Farm ManagementklhwongWA 0ms14156kbC++171.5kb2024-11-09 16:09:502024-11-09 16:10:05

Judging History

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

  • [2024-11-09 16:10:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14156kb
  • [2024-11-09 16:09:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
const int N = 1000007;

struct segtree {
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define mid ((l + r) >> 1)
    ll cnt[N << 2], sum[N << 2];
    void pushup(int rt) {
        cnt[rt] = cnt[ls] + cnt[rs];
        sum[rt] = sum[ls] + sum[rs];
    }
    void upd(int rt, int l, int r, int p, ll num) {
        if (l == r) {
            cnt[rt] += num;
            sum[rt] += 1ll * num * l;
            return;
        }
        p <= mid ? upd(ls, l, mid, p, num) : upd(rs, mid + 1, r, p, num);
        pushup(rt);
    }
    ll ksum(int rt, int l, int r, ll k) {
        if (l == r) {return 1ll * l * k;}
        if (cnt[rs] >= k) return ksum(rs, mid + 1, r, k);
        return sum[rs] + ksum(ls, l, mid, k - cnt[rs]);
    }
} tr;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<tuple<ll, ll, ll>> s;
    int n;
    ll m;
    cin >> n >> m;
    ll totalL = 0;
    for(ll i = 0; i < n; i++){
        ll w, l , r;
        cin >> w >> l >> r;
        s.eb(w,l,r);
        totalL += w*l; m-=l;
    }
    sort(all(s));
    ll ans = totalL + m * get<0>(s.back());
    for(auto[w,l,r]:s){
        ll tmp = m+l;
        ll tmptot = totalL - w*l;
        if (tr.cnt[1] < tmp) tmptot += tr.sum[1] + w * (tmp - tr.cnt[1]);
        else tmptot += tr.ksum(1, 1, N-1, tmp);
        ans = max(ans, tmptot);
        tr.upd(1, 1, N-1, w, r-l);
    }
    cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

99

result:

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