QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687577#9529. Farm ManagementrefRE 1ms7716kbC++203.9kb2024-10-29 19:49:312024-10-29 19:49:31

Judging History

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

  • [2024-10-29 19:49:31]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7716kb
  • [2024-10-29 19:49:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e5+10;
const int M=1e6+10;
struct node
{
    ll w,l,r;
}a[100010];
bool cmp(node b,node c)
{
    if(b.w<c.w)
    {
        return 1;
    }
    else if(b.w==c.w)
    {
        if(b.l<c.l)
        {
            return 1;
        }
        else if(b.l==c.l)
        {
            if(b.r<c.r)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else
            return 0;
    }
    else
        return 0;
}
ll dp[M];
ll vis[N];
ll c[N];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    ll n,m;
	while(cin>>n>>m)
	{
        ll ans=0;
        ll cnt=0;
        ll maxx=0;
        for(int i=1;i<=n;i++)
        {
            vis[i]=-1;
            cin>>a[i].w>>a[i].l>>a[i].r;
            ans+=(a[i].w*a[i].l);
            cnt+=a[i].l;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            c[i]=a[i].l;
        }
        maxx=ans+(m-cnt)*a[n].w;
        ll st=n;
        ll sum=0;
        dp[0]=0;
        for(int i=n;i>=1;i--)
        {
            if(cnt+a[i].r-a[i].l<m)
            {
                ans=ans+(a[i].w)*(a[i].r-a[i].l);
                cnt=cnt+a[i].r-a[i].l;
                c[i]=a[i].r;
            }
            else
            {
                ans=ans+(a[i].w)*(m-cnt);
                if(m-cnt==a[i].r-a[i].l)
                {
                    c[i]=a[i].r;
                    st=i-1;
                    while(a[i].r!=a[i].l)
                    {
                        st--;
                        if(st==0)
                        {
                            break;
                        }
                    }
                    sum=0;
                }
                else
                {
                    st=i;
                    sum=m-cnt;
                    c[i]+=(m-cnt);
                }
                break;
            }
        }
        maxx=max(ans,maxx);
        ll j=st;
        ll maxn=0;
        for(int i=1;i<=(int)1e6;i++)
        {   
            while(a[st].l+sum==a[st].r)
            {
                st--;
                sum=0;
                if(st==0)
                {
                    break;
                }
            }
            if(st==0)
            {
                maxn=i-1;
                break;
            }
            sum++;
            if(i==1||sum==1)
            {
                vis[st]=i;
            }
            dp[i]=dp[i-1]+a[st].w;
        }
        if(maxn==0)
        {
            maxn=(int)1e6;
        }
        for(int i=1;i<=j;i++)
        {
            if(c[i]>maxn)
            {
                if(vis[i]==-1)
                {
                    maxx=max(maxx,ans-a[i].w*maxn+dp[maxn]);
                }
                else
                {
                    if(maxn<vis[i])
                    {
                        maxx=max(maxx,ans-a[i].w*maxn+dp[maxn]);
                    }
                    else
                    {
                        maxx=max(maxx,ans-a[i].w*maxn+a[i].w*(maxn-vis[i]+1)+dp[vis[i]-1]);
                    }
                }

            }
            else
            {
                if(vis[i]==-1)
                {
                    maxx=max(maxx,ans-a[i].w*c[i]+dp[c[i]]);
                }
                else
                {
                    if(c[i]<vis[i])
                    {
                        maxx=max(maxx,ans-a[i].w*c[i]+dp[c[i]]);
                    }
                    else
                    {
                        maxx=max(maxx,ans-a[i].w*c[i]+a[i].w*(c[i]-vis[i]+1)+dp[vis[i]-1]);
                    }
                }
            }
        }
        cout<<maxx<<endl;
    }
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

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: 1ms
memory: 7716kb

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
Runtime Error

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:


result: