QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693743 | #9529. Farm Management | panelope | WA | 1ms | 7820kb | C++14 | 1.2kb | 2024-10-31 16:40:24 | 2024-10-31 16:40:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
long long m;
struct ty{
long long w,l,r;
}a[100010];
bool cmp(ty x, ty y){
return x.w<y.w;
}
long long t[100010];
long long rt[100010];
long long wt[100010];
int main(){
int T = 1;
while(T--)
{
cin >> n >> m;
long long ans = 0;
long long s = 0, cur = 0;
for(int i=1; i<=n; i++){
cin >> a[i].w >> a[i].l >> a[i].r;
}
sort(a+1, a+1+n, cmp);
long long sum = 0;
for(int i=1; i<=n; i++){
t[i] = a[i].l;
m -= a[i].l;
sum += a[i].w * a[i].l;
}
ans = sum+m*a[n].w;
for(int i=n; i>=1; i--){
if(m>a[i].r-t[i]){
m -= a[i].r-t[i];
sum += a[i].w*(a[i].r-t[i]);
t[i] = a[i].r;
}
else{
sum += a[i].w*m;
t[i] += m;
m = 0;
break;
}
}
for(int i=n; i>=1; i--){
rt[i] = rt[i+1] + a[i].r - t[i];
wt[i] = wt[i+1] + a[i].w * (a[i].r - t[i]);
}
for(int i=n-1; i>=1; i--){
long res = 0;
long l = i+1, r = n;
while(l<=r){
long long mid = (l+r)/2;
if(t[i]>=rt[mid]){
r = mid-1;
}
else
l = mid+1;
}
res = wt[l] - t[i]*a[i].w + (t[i]-t[l])*a[l-1].w;
ans = max(ans,sum+res);
}
cout << ans << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7820kb
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: 5752kb
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:
36681121
result:
wrong answer 1st lines differ - expected: '35204500', found: '36681121'