-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path16B.cpp
More file actions
46 lines (46 loc) · 746 Bytes
/
Copy path16B.cpp
File metadata and controls
46 lines (46 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
*Author:Yashasvi Goel
*Date:3/17/19
*/
#include<bits/stdc++.h>
struct pair{
int a,b;
};
bool comp(pair a,pair b)
{
if(a.b>b.b)
return 1;
else
return 0;
}
using std::sort;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
struct pair coll[m];
int x,y;
for(int i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
coll[i].a=x;
coll[i].b=y;
}
sort(coll,coll+m,comp);
int c=0,k=0;
for(int i=0;i<m;i++)
{
if(c+coll[i].a<=n)
{
c=c+coll[i].a;
k+=coll[i].a*coll[i].b;
}
else
{
k+=coll[i].b*(n-c);
c=n;
}
}
printf("%d\n",k);
return 0;
}