QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684582 | #9529. Farm Management | _LSA_# | WA | 1ms | 5676kb | C++14 | 1.7kb | 2024-10-28 14:31:39 | 2024-10-28 14:31:44 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
ll X = 0 ,r = 1;
char ch = getchar();
while(!isdigit(ch) && ch != '-') ch = getchar();
if(ch == '-') r = -1,ch = getchar();
while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
return X*r;
}
const int N = 1e5+10;
int n; ll m,ans;
struct node{
ll w,l,r;
}a[N];
ll suf[N],valsuf[N],pre[N],valpre[N];
ll s1[N],s2[N];
void solve(){
n = read(); m = read();
for(int i=1;i<=n;i++){
ll w = read(),l = read(),r = read();
a[i] = node{w,l,r};
}
sort(a+1,a+1+n,[](node x,node y){return x.w == y.w ? x.l < y.l : x.w > y.w;});
for(int i=n;i;i--){
suf[i] += a[i].l+suf[i+1];
valsuf[i] += a[i].l*a[i].w+valsuf[i+1];
}
for(int i=1;i<=n;i++){
pre[i] += pre[i-1]+a[i].l;
valpre[i] += valpre[i-1]+a[i].l*a[i].w;
}
// for(int i=1;i<=n;i++) cout << a[i].w << " " << a[i].l << " " << a[i].r << "\n";
for(int i=1;i<=n;i++){
ll rest = m-(pre[i-1]+suf[i+1]);
int id = upper_bound(s1,s1+i,rest)-s1-1;
// cout << id << " " << s1[id] << " " << s2[id] << "\n";
rest -= s1[id];
assert(rest >= 0 && (rest < s1[id+1] || id+1 == i) && id >= 0);
ll now = valpre[i-1]+valsuf[i+1]+s2[id];
now += rest*a[id].w;
ans = max(ans,now);
s1[i] = s1[i-1]+a[i].r-a[i].l;
s2[i] = s2[i-1]+(a[i].r-a[i].l)*a[i].w;
}
cout << ans;
}
signed main(){
int T = 1;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5676kb
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: 5672kb
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:
34950156
result:
wrong answer 1st lines differ - expected: '35204500', found: '34950156'