QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682157#9529. Farm ManagementOneWan#WA 1ms5692kbC++231.6kb2024-10-27 14:12:562024-10-27 14:12:57

Judging History

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

  • [2024-10-27 14:12:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5692kb
  • [2024-10-27 14:12:56]
  • 提交

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'