QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810952#9529. Farm ManagementfzxWA 2ms11912kbC++141.2kb2024-12-12 13:54:172024-12-12 13:54:18

Judging History

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

  • [2024-12-12 13:54:18]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11912kb
  • [2024-12-12 13:54:17]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long 
#define pb push_back
using namespace std;
const int INF=1e6+5;
int n,m,w[INF],p[INF],l[INF],r[INF],S[INF],S2[INF];
void solve() {
    cin>>n>>m;int suml=0,res=0,ans=0;
    for (int i=1;i<=n;i++) {
        cin>>w[i]>>l[i]>>r[i];
        suml+=l[i];res+=l[i]*w[i];
        p[i]=i;
    }
    sort(p+1,p+1+n,[](int x,int y){return w[x]>w[y];});
    for (int i=1;i<=n;i++) 
        S[i]=S[i-1]+(r[p[i]]-l[p[i]]),
        S2[i]=S2[i-1]+(r[p[i]]-l[p[i]])*w[p[i]];
    for (int i=1;i<=n;i++) {
        int s1=suml-l[p[i]],r1=res-l[p[i]]*w[p[i]];
        s1=m-s1;
        if (s1>=S[i-1]) 
            ans=max(ans,r1+(s1-S[i-1])*w[p[i]]+S2[i-1]);
        else {
            int L=1,R=i-1,ans=-1;
            while (L<=R) {
                int Mid=(L+R)>>1;
                if (S[Mid]>=s1) R=(ans=Mid)-1;
                else L=Mid+1;
            }
            assert(ans!=-1);
            int it=S2[ans-1]+r1+(s1-S[ans-1])*w[p[ans]];
            ans=max(ans,it);
        }
        // int L=1,R=i,ans=-1;
        // ans=max(ans,res-l[i]*)
    }
    cout<<ans<<"\n";
}
signed main()
{
    ios::sync_with_stdio(false);
    int t=1;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11912kb

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: 0ms
memory: 11844kb

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:

32281150

result:

wrong answer 1st lines differ - expected: '35204500', found: '32281150'