6 solutions

  • 1
    @ 2021-10-17 16:43:15

    题意分析:

    不知道有没有小伙伴和我一样,没有第一时间读懂题

    这里有一句非常关键的句子"比赛时间分成n个时段~~~~~~每个时间必须在规定时限t前完成。"深入理解到他的意思,我们就可以用一个bool数组来实现了

    注意:

    为了更多的钱,将扣钱多的先安排,且从边界倒序遍历。

        #include<cstdio>
        #include<cstring>
        #include<cmath>
        #include<algorithm>
        typedef long long ll;
        using namespace std;
        bool vis[505];
        struct node{
        	int e,b;
        }a[1003];
        int cmp(node x,node y)
        {
        	if(x.e==y.e) return x.b>y.b;
        	return x.e > y.e;
        
        }
        int main()
        {
        	ll m,n;
        	scanf("%lld%lld",&m,&n);
        	for(int i = 1;i <= n;i++)
        	{
        		scanf("%d",&a[i].b);
        	}
        	for(int i = 1;i <= n;i++)
        	{
        		scanf("%d",&a[i].e);
        	}
        	sort(a + 1,a + n + 1,cmp); 
        	for(int i=1;i<=n;i++)
        {
            if(!vis[a[i].b])
            {
                vis[a[i].b]=true;
            }
            else
            {
                int j;
                for(j=a[i].b-1;j>0;j--)
                {
                    if(!vis[j])
                    {
                        vis[j]=true;
                        break;
                    }
                }
                if(j==0)
                {
                    m-=a[i].e;
                }
            }
        }
        printf("%lld\n",m);
        return 0;	
        }
    
    

    Information

    ID
    94
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    90
    Accepted
    48
    Uploaded By