其他分享
首页 > 其他分享> > 【Google kick start】Fesitival

【Google kick start】Fesitival

作者:互联网

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int t,n,d,k;
    scanf("%lld",&t);
    for(int p=1;p<=t;p++)
    {
        printf("Case #%lld: ",p);
        multiset<int>s;
		multiset<int, greater<int>>s2;
        vector<int> startday[300010],endday[300010];
        int happy,from,to;
		long long happysum=0,maxhappy=0;
        scanf("%lld%lld%lld",&n,&d,&k);
        while(d--)
        {
            scanf("%lld%lld%lld",&happy,&from,&to);
            startday[from].push_back(happy);
            endday[to].push_back(happy);
        }
        for(int i=1;i<=n;i++)
        {
			for(auto x:startday[i])
			{
				if(s.size()<k)
				{
					s.insert(x);
					happysum+=x;
				}
				else
				{
					int s_min=*s.begin();
					if(s_min<x)
					{
						s2.insert(*s.begin());
						s.erase(s.begin());
						s.insert(x);
						happysum-=s_min;
						happysum+=x;
					}
					else
					{
						s2.insert(x);
					}
				}
			}
			
            if(maxhappy<happysum)maxhappy=happysum;
            
			for(auto x:endday[i])
			{
				if(s.find(x)!=s.end())
				{
					s.erase(s.find(x));
					happysum-=x;
					if(s2.size()>0)
					{
						s.insert(*s2.begin());
						happysum+=*s2.begin();
						s2.erase(s2.begin());
					}
				}
				else
				{
					s2.erase(s2.find(x));
				}
			}
        }
        printf("%lld\n",maxhappy);
    }
    return 0;
}

标签:Google,int,s2,long,start,Fesitival,lld%,happy,lld
来源: https://www.cnblogs.com/tsyxxxka/p/15344639.html