Educational Codeforces Round 62 (Rated for Div. 2) C
程序员文章站
2022-06-04 18:14:07
...
贪心思想
#include<iostream>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<string>
#include<cstdio>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
const int N=2e6+10;
typedef long long ll;
int n,k;
pair<int ,int >a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>a[i].second>>a[i].first;
}
sort(a,a+n);
ll sum=0;
ll res=0;
set<pair<int ,int > >s;
for(int i=n-1;i>=0;i--)
{
s.insert(make_pair(a[i].second,i));//再次排序将长度短的歌曲弹出
sum+=a[i].second;
while(s.size()>k)
{
set<pair<int ,int> >::iterator it=s.begin();
sum-=it->first;
s.erase(it);
}
res=max(res,sum*a[i].first);
}
cout<<res<<endl;
}
上一篇: include与require的区别
推荐阅读
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree
-
Codeforces Round #432 (Div. 2) - C - Five Dimensional Points
-
Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
-
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution(多颗树状数组+思维)
-
【解题报告】Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)
-
Codeforces Round #658 (Div. 2)C1. Prefix Flip (Easy Version)(贪心)
-
Codeforces Round #658 (Div. 2) (C1、C2)
-
Codeforces Round #320 (Div. 2) C. A Problem about Polyline ( 数学 )