Codeforces Round #610 (Div. 2)C. Petya and Exam

Topic Source: http://codeforces.com/contest/1282/problem/C

Meaning of the questions: There are n number of topics, digits 0 and 1 represents the simple or difficult, a, b to do a simple title or time of a puzzle, after an array represents a limited time, and asked how much to do in the 0-T Time Up a.

If you leave (0 <= T1 <= T), all have to do a limited time is less than T1, and is 0 otherwise. In T1

After doing a question, then there is still time to do it on the first take the simple question, greedy to make a choice, there is still time to go choose another.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct A{
    ll ed;
    ll t;
}aa[200100];
bool cmp(A t1,A t2)
{
	if(t1.t==t2.t)
	return t1.ed<t2.ed;
	return t1.t<t2.t;
}
int main()
{
    int m;
    scanf("%d",&m);
    while(m--)
    {
        ll cnt0=0;
        ll cnt1=0;
        ll n,T,a,b,i,j;
        cin>>n>>T>>a>>b;
        for(i=1;i<=n;i++)
        {
            cin>>aa[i].ed;
            if(aa[i].ed==0)
            cnt0++;
        }
        cnt1=n-cnt0;
        for(i=1;i<=n;i++)
        {
            cin>>aa[i].t;
        }
        sort(aa+1,aa+1+n,cmp);
        ll sum=0;
        ll ans=0;
        aa[n+1].t=T+1;
        aa[0].t=0;
        for(i=0;i<=n;i++)
        {
        	if(i)
        	{
        		if(aa[i].ed)
        		{
        			cnt1--;
        			sum+=b;
        		}
        		else
        		{
        			sum+=a;
					cnt0--;
        		}
			}
			if(sum>T)
			break;
			if(aa[i].t==aa[i+1].t)
			continue;
			if(sum<=aa[i+1].t-1)
			{
				ll num1=0;
				ll num0=min(cnt0,(aa[i+1].t-1-sum)/a);
				ll temp=aa[i+1].t-1-sum-num0*a;
				if(temp>0)
				num1=min(cnt1,temp/b);
				ans=max(ans,i+num1+num0);
			} 
		}
        printf("%I64d\n",ans);
    }
}

 

Published 56 original articles · won praise 17 · views 2317

Guess you like

Origin blog.csdn.net/weixin_43958964/article/details/103768508
Recommended