-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustumer.cpp
More file actions
57 lines (47 loc) · 1014 Bytes
/
custumer.cpp
File metadata and controls
57 lines (47 loc) · 1014 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
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define CusNum 50010
struct node
{
int num;
int money;
} cus[CusNum];
int cmp(node a, node b)
{
if (a.money == b.money)
return a.num > b.num;
return a.money > b.money;
}
int main()
{
int n, m;
vector<int> table(50000, 0);
int mark[CusNum];
int sum = 0;
memset(mark, 0, sizeof(mark));
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> table[i];
for (int i = 0; i < m; i++) {
cin >> cus[i].num;
cin >> cus[i].money;
}
sort(table.rbegin(), table.rend());
sort(cus, cus+m, cmp);
int i, j, k;
int max = 0;
for (int i = 0; i < n; i++) {
mark[table[i]]++;
if (table[i] > max)
max = table[i];
}
for (i = 0; i < m; i++) {
for (j = cus[i].num; j <= max; j++)
if (mark[j]) {
mark[j]--;
sum += cus[i].money;
break;
}
}
cout << sum;
}