-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path16B.cpp
More file actions
107 lines (107 loc) · 1.96 KB
/
16B.cpp
File metadata and controls
107 lines (107 loc) · 1.96 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*GOD IS GREAT,
SO AM I*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ford(i,a,n) for(long long int i=a;i<n;++i)
#define fore(i,a,n) for(long long int i=a;i<=n;i++)
#define test ll t;cin>>t;while(t--)
#define op(z) cout<<z<<endl
#define ops(z) cout<<z<<" "
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(x) cout<<#x<<" "<<x<<endl
#define pp pair<ll,ll>
#define maxe 1000000
#define MOD 1000000007
ll prime[maxe] = {0};
// TO COUNT THE DIGIT IN A NUMBER => floor(log10(n)+1)
void file()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll sumofdigits(ll n) {
ll sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
void sieve()
{
prime[0] = 0;
prime[1] = 0;
prime[2] = 1;
ll i, j, k;
file();
for (i = 3; i <= maxe; i += 2)
{
prime[i] = 1;
}
for (i = 3; i <= maxe; i++)
{
if (prime[i])
{
for (j = i * i; j <= maxe; j += 2 * i)prime[j] = 0;
}
}
}
bool cmp(pp &a, pp &b)
{
if (a.first != b.first)
{
return b.first > a.first;
}
else
{
return b.second > a.second;
}
}
void solve()
{
ll n, m, y;
cin >> n >> m;
pp match[m];
ford(i, 0, m)
{
cin >> match[i].second;
cin >> match[i].first;
}
sort(match, match + m, cmp);
ford(i, 0, m)
{
ops(match[i].first);
op(match[i].second);
}
ll ans = 0;
for (ll i = 0; i < m; i++)
{
if (n >= match[i].second)
{
ans += match[i].first * match[i].second;
n -= match[i].second;
}
else
{
ans += n * match[i].first;
n = 0;
}
if (n == 0)
break;
}
op(ans);
}
int main()
{
fastIO
//sieve();
file();
//test
{
solve();
}
return 0;
}