-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC121C.cpp
More file actions
40 lines (32 loc) · 695 Bytes
/
Copy pathABC121C.cpp
File metadata and controls
40 lines (32 loc) · 695 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
#include <stdio.h>
#include <stdlib.h>
struct pair{
long a;
int b;
};
int compare(const void *x, const void *y)
{
return ((struct pair *)x)->a - ((struct pair *)y)->a;
}
int main() {
int i,n,m;//‡Œv‹àŠz
scanf("%d %d\n",&n,&m);
struct pair AB[n];
for(i=0;i<n;i++){
scanf("%ld %d",&AB[i].a,&AB[i].b);
}
qsort(AB,n,sizeof(struct pair),compare);// ƒ\[ƒg
struct pair ab = {0,m};
for (i = 0; i < n; i++) {
if(ab.b <= AB[i].b){
ab.a += AB[i].a * ab.b;
break;
}
else{
ab.a += AB[i].a*AB[i].b;
ab.b -= AB[i].b;
}
}
printf("%ld\n", ab.a);
return 0;
}