QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685165 | #9529. Farm Management | Y_J_Y# | WA | 1ms | 7784kb | C++20 | 2.2kb | 2024-10-28 18:00:28 | 2024-10-28 18:00:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define root 1,n,1
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define pd __gnu_pbds
inline ll read() {
ll x=0,w=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
inline void print(__int128 x){
if(x<0) {putchar('-');x=-x;}
if(x>9) print(x/10);
putchar(x%10+'0');
}
#define maxn 1000010
#define int long long
const double eps=1e-8;
#define int_INF 0x3f3f3f3f
#define ll_INF 0x3f3f3f3f3f3f3f3f
struct Node{
int w,l,r;
bool operator < (const Node &rhs) const {
return w>rhs.w;
}
}node[maxn];
int lowbit(int x) {
return x&-x;
}
int tree[maxn];int limit=2e5;
void Add(int pos,int val) {
while(pos<=limit) {
tree[pos]+=val;
pos+=lowbit(pos);
}
}
int Query(int pos) {
int ans=0;
while(pos) {
ans+=tree[pos];
pos-=lowbit(pos);
}
return ans;
}
int lsum1[maxn],lsum2[maxn];
signed main() {
int n=read();int m=read();
int sum=0;int sum2=0;
for(int i=1;i<=n;i++) {
node[i].w=read();node[i].l=read();node[i].r=read();
sum+=node[i].l;
sum2+=node[i].l*node[i].w;
Add(i,node[i].r-node[i].l);
lsum1[i]=lsum1[i-1]+node[i].l*node[i].w;
lsum2[i]=lsum2[i-1]+node[i].r*node[i].w;
}
sort(node+1,node+n+1);
int ans=-1;
ans=max(ans,sum2+node[1].w*(m-sum));
for(int i=1;i<=n;i++) {
int opt=m-sum+node[i].l;
Add(i,-(node[i].r-node[i].l));
if(opt>=Query(n)) {
ans=max(ans,lsum2[n]-node[i].r*node[i].w+(opt-Query(n))*node[i].w);
}
else {
int l=1,r=n;int pos=-1;
while(l<=r) {
int mid=(l+r)>>1;
if(opt>=Query(mid)) {
pos=mid;
l=mid+1;
}
else {
r=mid-1;
}
}
if(pos==-1) {
ans=max(ans,lsum1[n]-node[i].l*node[i].w+opt*node[1].w);
}
else {
if(pos-1>=i) {
ans=max(ans,lsum2[pos-1]-node[i].r*node[i].w+lsum1[n]-lsum1[pos]+(opt-Query(pos-1))*node[pos].w);
}
else {
ans=max(ans,lsum2[pos-1]+lsum1[n]-lsum1[pos]-node[i].l*node[i].w+(opt-Query(pos-1))*node[pos].w);
}
}
}
Add(i,node[i].r-node[i].l);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7784kb
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: 7780kb
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:
31758380
result:
wrong answer 1st lines differ - expected: '35204500', found: '31758380'