QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696523 | #9529. Farm Management | yukino | WA | 0ms | 3584kb | C++17 | 1.9kb | 2024-10-31 23:05:53 | 2024-10-31 23:05:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
const int N=1e6+10;
const int M=1e6+10;
int mod=998244353;
#define lowbit(x) ((x)&(-x))
#define int long long
using namespace std;
struct node
{
int w,l,r,cur;
bool operator <(const node &others)const {
return w < others.w;
}
};
void solve()
{
int n,m;
cin>>n>>m;
vector<int>worth(n+2),need(n+2);
vector<node>v(n+1);
for(int i=1;i<=n;i++)
{
cin>>v[i].w>>v[i].l>>v[i].r;
}
sort(v.begin()+1,v.end());
int sum=0;
int cnt=m;
for(int i=1;i<=n;i++)
{
sum+=v[i].w*v[i].l;
v[i].cur=v[i].l;
cnt-=v[i].l;
}
int res=0;
for(int i=n;i>=1;i--)
{
res=max(res,sum+v[i].w*(cnt));
if(v[i].r-v[i].cur<=cnt)
{
sum+=v[i].w*(v[i].r-v[i].cur);
cnt-=(v[i].r-v[i].cur);
v[i].cur=v[i].r;
}else
{
sum+=cnt*v[i].w;
v[i].cur+=cnt;
cnt=0;
break;
}
}
for(int i=n;i>=1;i--)
{
int k=v[i].r-v[i].cur;
need[i]=need[i+1]+k;
worth[i]=worth[i+1]+k*v[i].w;
}
for(int i=n;i>=1;i--)
{
int p=v[i].cur;
if(p==0)
{
continue;
}
int l1=i,r1=n;
int ans=0;
while(l1<=r1) {
int mid = (l1 + r1) / 2;
if (need[mid] <= p) {
ans = mid;
r1 = mid - 1;
} else {
l1 = mid + 1;
}
}
int tmp=sum+v[p-1].w*(p-need[ans])+worth[ans]-v[i].w*p;
res=max(res,tmp);
}
cout<<res;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3580kb
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:
34859047
result:
wrong answer 1st lines differ - expected: '35204500', found: '34859047'