QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#728793#9529. Farm ManagementklhwongWA 3ms13900kbC++171.5kb2024-11-09 15:56:212024-11-09 15:56:26

Judging History

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

  • [2024-11-09 15:56:26]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13900kb
  • [2024-11-09 15:56:21]
  • 提交

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) { //add num at positiona p
        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<int, int, int>> s;
    ll n, m;
    cin >> n >> m;
    ll totalL = 0;
    for(ll i = 0, w, l, r; i < n; i++){
        cin >> w >> l >> r;
        s.eb(w,l,r);
        totalL += w*l; m-=l;
    }
    sort(all(s));
    ll ans = totalL + m * get<0>(s.front());
    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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 13900kb

input:

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

output:

89

result:

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