QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694794 | #9529. Farm Management | xiey# | WA | 0ms | 3624kb | C++23 | 2.1kb | 2024-10-31 18:40:20 | 2024-10-31 18:40:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll n, m;
cin >> n >> m;
vector<pair<ll, pair<ll, ll>>> a(n+1);
ll sum = 0, num = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i].first >> a[i].second.first >> a[i].second.second;
sum += a[i].second.first * a[i].first;
num += a[i].second.first;
}
sort(a.begin()+1, a.end());
ll b[n+2]={0},c[n+2]={0};
for(int i=n;i>=1;i--)
{
b[n-i+1]=b[n-i]+a[i].second.second-a[i].second.first;
c[n-i+1]=c[n-i]+(a[i].second.second-a[i].second.first)*a[i].first;
}
ll ma=0,pos=0;
// for(int i=1;i<=n;i++)
// cout<<b[i]<<' ';
// cout<<endl;
// for(int i=1;i<=n;i++)
// cout<<c[i]<<' ';
// cout<<endl;
for (int i = 1; i <= n; i++)
{
int l=1,r=n;
while(l+1<r)
{
int mid=(l+r)/2;
if(b[mid]<a[i].second.first+m-num)
{
r=mid;
}
else {
l=mid;
}
}
// cout<<a[i].second.first+m-num<<' '<<l<<endl;
if(n-l<i)
break;
if(ma<(sum+c[l]+(a[i].second.first+m-num-b[l])*a[n-l].first))
{
ma=(sum+c[l]+(a[i].second.first+m-num-b[l])*a[n-l].first);
pos=i;
}
}
// ll a1 = sum + (m - num) * a.back().first;
ll a2 = sum - a[pos].first * a[pos].second.first;
m -= num - a[pos].second.first;
for (int i = n; i >= 1; i--)
{
if (i == pos)
continue;
if (m < a[i].second.second - a[i].second.first)
{
a2 += m * a[i].first;
m = 0;
break;
}
else
{
a2 += (a[i].second.second - a[i].second.first) * a[i].first;
m -= a[i].second.second - a[i].second.first;
}
}
// cout<<a1<<' '<<a2<<'\n';
cout <<a2;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 0
Accepted
time: 0ms
memory: 3620kb
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:
35204500
result:
ok single line: '35204500'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3480kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
14852304
result:
wrong answer 1st lines differ - expected: '22000255', found: '14852304'