标签:技术 min div tor ide output ini for 图片
C. Playlist
You have a playlist consisting of n songs. The i-th song is characterized by two numbers ti and bi — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to a set of 3 songs having lengths [5,7,4] and beauty values [11,14,6] is equal to (5+7+4)⋅6=96.
You need to choose at most k songs from your playlist, so the pleasure of listening to the set of these songs them is maximum possible.
Input
The first line contains two integers n and k (1≤k≤n≤3⋅105) – the number of songs in the playlist and the maximum number of songs you can choose, respectively.
Each of the next n lines contains two integers ti and bi (1≤ti,bi≤106) — the length and beauty of i-th song.
Output
Print one integer — the maximum pleasure you can get.
Examples
input
4 3
4 7
15 1
3 6
6 8
output
78
input
5 3
12 31
112 4
100 100
13 55
55 50
output
10000
Note
In the first test case we can choose songs 1,3,4, so the total pleasure is (4+3+6)⋅6=78.
In the second test case we can choose song 3. The total pleasure will be equal to 100⋅100=10000.
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 3e5+9; 4 typedef long long ll; 5 struct qwq { 6 ll t, b; 7 } s[ N ]; 8 9 bool cmp( qwq a, qwq b ) { 10 return a.b > b.b; 11 } 12 13 int main( void ) { 14 int n, m; 15 priority_queue< int, vector< int >, greater< int > > q; 16 scanf( "%d%d", &n, &m ); 17 for( int i = 0; i < n; ++i ) { 18 scanf( "%lld%lld", &s[ i ].t, &s[ i ].b ); 19 } 20 sort( s, s + n, cmp ); 21 ll sum = 0, ans = 0; 22 for( int i = 0; i < n; ++i ) { 23 sum += s[ i ].t; 24 q.push( s[ i ].t ); 25 if( i > m - 1 ) { 26 sum -= q.top(); 27 q.pop(); 28 } 29 ans = max( sum * s[ i ].b, ans ); 30 } 31 printf( "%lld\n", ans ); 32 return 0; 33 }
标签:技术 min div tor ide output ini for 图片
原文地址:https://www.cnblogs.com/ACirno/p/10610505.html