QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747298#9529. Farm ManagementSSHLWA 0ms3656kbC++201.9kb2024-11-14 16:49:212024-11-14 16:49:22

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 16:49:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-11-14 16:49:21]
  • 提交

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 t[n+1]={0},cnt=0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].first >> a[i].second.first >> a[i].second.second;
        cnt += a[i].second.second;
    }
    sort(a.begin()+1, a.end());
    for(int i=1;i<=n;i++)
    {
        if(cnt-m>=a[i].second.second-a[i].second.first)
        {
            t[i]=a[i].second.first;
            cnt-=a[i].second.second-a[i].second.first;
        }else{
            t[i]=a[i].second.second-cnt+m;
            cnt=m;
        }
    }
    ll p[n+2]={0},q[n+2]={0};
    for(int i=n;i>=1;i--)
    {
        p[n-i+1]=p[n-i]+t[n-i+1]-a[n-i+1].second.first;
        q[n-i+1]=q[n-i]+(t[n-i+1]-a[n-i+1].second.first)*a[n-i+1].first;
    }
    ll d[n+2]={0},e[n+2]={0};
    for(int i=n;i>=1;i--)
    {
        d[n-i+1]=d[n-i]-t[i]+a[i].second.second;
        e[n-i+1]=e[n-i]+(-t[i]+a[i].second.second)*a[i].first;
    }
    // for(int i=1;i<=n;i++)
    // {
    //     cout<<a[i].first<<' '<<a[i].second.first<<' '<<a[i].second.second<<' '<<t[i]<<' '<<p[i]<<' '<<q[i]<<' '<<d[i]<<' '<<e[i]<<'\n';
    // }
    ll a3=0;
    for(int i=1;i<=n;i++)
    {
        a3=max(a3,p[i]*a[i].first-q[i]);
    }
    ll a2=0;
    for(int i=1;i<=n;i++)
    {
        ll l=1,r=n-i;
        while(l+1<r)
        {
            ll mid=(l+r)/2;
            if(d[mid]<t[i])
            l=mid;
            else r=mid;
        }
        a2=max(a2,e[r]-a[i].first*(d[r]));
        // cout<<r<<'\n';
    }
        // cout<<a2<<' '<<a3;
    for(int i=1;i<=n;i++)
    {
        a3+=t[i]*a[i].first;
        a2+=t[i]*a[i].first;
    }
    // cout<<a2<<' '<<a3;
    cout<<max(a2,a3);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin>>t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

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: 3656kb

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:

39093934

result:

wrong answer 1st lines differ - expected: '35204500', found: '39093934'