Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- , \ / ,
- / \ )\__/( / \
- / \ (_\ /_) / \
- ____/_____\__\@ @/___/_____\____
- | |\../| |
- | \VV/ |
- | ------___------- |
- |__________Chuta Dragon___________|
- | /\ / \\ \ /\ |
- | / V )) V \ |
- |/ ` // ' \|
- ` V '
- */
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
- #define fi first
- #define se second
- #define pb push_back
- #define eb emplace_back
- void input(ll ara[],ll n)
- {
- for(ll i=0; i<n; i++)cin>>ara[i];
- }
- #define eb emplace_back
- int main() {
- multimap<ll,ll>m;
- ll n,m1,a,b;
- cin>>n>>m1;
- for(ll i=0; i<m1;i++)
- {
- cin>>b>>a;
- //m[a]=b;
- m.insert({a,b});
- }
- vector<pair<ll,ll>>v;
- // cout<<endl;
- for(auto x:m)
- {
- a=x.fi;
- b=x.se;
- // cout<<a<<" "<<b<<endl;
- v.pb({a,b});
- }
- ll cnt=0,ans=0;
- // cout<<endl;
- for(ll i=m1-1; ;i--)
- { // cout<<v[i].fi<<" "<<v[i].se<<endl;
- if(v[i].se<n)
- {
- ans=ans+(v[i].fi*v[i].se);
- n=n-v[i].se;
- if(i==0)break;
- }
- else
- {
- ans=ans+(n*v[i].fi);
- break ;
- }
- }
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement