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];
- // if(ara[i]>mx)mx=ara[i];
- // if(ara[i]<mn)mn=ara[i];
- // m[ara[i]]++;
- }
- }
- #define eb emplace_back
- int main()
- {
- ll n,m,a,b,i;
- cin>>n>>m;
- vector<pair<ll,ll>>v;
- while(m--)
- {
- cin>>a>>b;
- v.pb({b,a});
- }
- sort(v.rbegin(),v.rend());
- int x=0,ans=0;
- for(i=0;i<v.size();i++)
- {
- if((x+v[i].second)<=n)
- {
- ans+=(v[i].first*v[i].second);
- x+=v[i].second;
- }
- else
- {
- int p=n-x;
- ans+=(p*v[i].first);
- break;
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement