QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728793 | #9529. Farm Management | klhwong | WA | 3ms | 13900kb | C++17 | 1.5kb | 2024-11-09 15:56:21 | 2024-11-09 15:56:26 |
Judging History
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'