QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682157 | #9529. Farm Management | OneWan# | WA | 1ms | 5692kb | C++23 | 1.6kb | 2024-10-27 14:12:56 | 2024-10-27 14:12:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
using i64 = long long;
struct node{
int w,l,r;
bool operator < (const node other)const{
return w>other.w;
}
};
node a[100005];
int tr[100005];
int tr2[100005];
int n;
int lowbit(int x){
return x&(-x);
}
void add(int x,int val,int cost){
while(x<=n){
tr[x]+=val;
tr2[x]+=val*cost;
x+=lowbit(x);
}
}
pair<int,int> get(int x){
int ans=0;
int ans2=0;
while(x){
ans+=tr[x];
ans2+=tr2[x];
x-=lowbit(x);
}
return {ans,ans2};
}
int m;
int total=0;
bool check(int mid){
return get(mid).first+total<=m;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i].w>>a[i].l>>a[i].r;
}
int res=0;
sort(a+1,a+1+n);
int p=0;
for(int i=1;i<=n;i++){
add(i,a[i].r-a[i].l,a[i].w);
total+=a[i].l;
p+=a[i].l*a[i].w;
}
for(int i=1;i<=n;i++){
add(i,-(a[i].r-a[i].l),a[i].w);
p-=a[i].l*a[i].w;
int l=1;
int r=n;
total-=a[i].l;
while(l<r){
int mid=(l+r+1)/2;
if(check(mid)){
l=mid;
}else{
r=mid-1;
}
}
auto [x,y]=get(l);
int k=m-total-x;
int ans=y+k*a[l+1].w+p;
res=max(ans,res);
p+=a[i].l*a[i].w;
add(i,a[i].r-a[i].l,a[i].w);
total+=a[i].l;
}
cout<<res<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
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: 1ms
memory: 5692kb
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:
35309054
result:
wrong answer 1st lines differ - expected: '35204500', found: '35309054'