Educational Codeforces Round 62 (Rated for Div. 2) C. Playlist

 一开始肯定要排个序,b相同时t大的在前边,不同时b大的在前面。

然后想最多只能选k个的限制,可以这样想,每次用到的b只能用已选到的最小的值,那可以把每个b都枚举一遍,然后每一次选时长最长的,且b大于等于当前的b的那k个不就好了吗,时间复杂度也才O(n),然后考虑怎么才能每次快速地选到最大的,这时候就可以考虑优先队列了,每次排序都是logn的复杂度,nlogn,完美。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

const int N = 300010;

int n, k;
struct Node
{
	int a, b;
}songs[N];

bool cmp(Node A, Node B)
{
	if(A.b == B.b)return A.a > B.a;
	return A.b > B.b;
}

int main()
{
	IOS
	cin >> n >> k;
	for(int i = 1; i <= n; i ++)
	{
		cin >> songs[i].a >> songs[i].b;
	}
	
	sort(songs + 1, songs + 1 + n, cmp);
	
	//cout << endl;
	//for(int i = 1; i <= n; i ++)cout << songs[i].a << ' ' << songs[i].b << endl;
	priority_queue<int, vector<int>, greater<int>> q;
	ll ans = 0, res = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(q.size() < k)
		{
			q.push(songs[i].a);
			res += songs[i].a;
		}
		else if(songs[i].a > q.top())
		{
			res -= q.top();
			res += songs[i].a;
			q.pop();
			q.push(songs[i].a);
		}
		
		ans = max(ans, res * songs[i].b);
	}
	cout << ans << endl;
	
	return 0;
}

Problem - 1140C - Codeforces

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值