QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701164 | #9529. Farm Management | Forever_Young# | WA | 0ms | 6028kb | C++23 | 1.3kb | 2024-11-02 13:51:01 | 2024-11-02 13:51:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define data dataa
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
const int N=int(1e5)+10;
struct Data
{
int w,l,r;
void scan(){scanf("%d%d%d",&w,&l,&r);}
bool operator<(const Data&a)const{return w<a.w;}
}a[N];
LL sl[N],sr[N],ansl[N],ansr[N],m;
int n;
int main()
{
scanf("%d%lld",&n,&m);
rep(i,n)a[i].scan();
sort(a+1,a+n+1);
for(int i=n;i;i--)
{
sl[i]=sl[i+1]+a[i].l;
sr[i]=sr[i+1]+a[i].r;
ansl[i]=ansl[i+1]+LL(a[i].w)*a[i].l;
ansr[i]=ansr[i+1]+LL(a[i].w)*a[i].r;
}
LL ans=0;
for(int i=n;i;i--)
{
if(sl[1]-sl[i]+sr[i+1]<=m)
{
ans=max(ans,ansl[1]-ansl[i]+ansr[i+1]+(m-(sl[1]-sl[i]+sr[i+1]))*a[i].w);
continue;
}
int l=i,r=n+1;
LL base=sl[1]-sl[i];
for(;l<r-1;)
{
int mid=(l+r)>>1;
if(base+sl[i+1]-sl[mid]+sr[mid]>=m)l=mid;else r=mid;
}
ans=max(ans,ansl[1]-ansl[i]+ansr[l+1]+ansl[i+1]-ansl[l]+(m-base-(sl[i+1]-sl[l]+sr[l+1]))*a[r].w);
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3984kb
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: 6028kb
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:
35800033
result:
wrong answer 1st lines differ - expected: '35204500', found: '35800033'