We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 81d2fdb commit ef496b9Copy full SHA for ef496b9
16B.cpp
@@ -0,0 +1,34 @@
1
+#include<bits/stdc++.h>
2
+using namespace std;
3
+
4
+int main(){
5
+ ios_base::sync_with_stdio(false);
6
+ cin.tie(NULL);
7
+ int n, m;
8
+ cin>>n>>m;
9
10
+ multimap <int, int, greater<int>> marr;
11
+ int x, y;
12
+ for(int i = 0; i < m; i++){
13
+ cin>>x>>y;
14
+ marr.insert(pair <int, int> (y, x));
15
16
+ }
17
18
+ multimap <int, int> :: iterator itr;
19
+int count = 0, sum = 0;
20
+for (itr = marr.begin(); itr != marr.end(); ++itr)
21
+{
22
+ count += itr->second;
23
+ if(count >= n){
24
+ itr->second = itr->second - (count - n);
25
+ sum += itr->first * itr->second;
26
+ break;
27
28
29
30
31
+}
32
+cout <<sum<< endl;
33
34
0 commit comments