Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* problem link:
- https://www.spoj.com/problems/MSCHED/en/ */
- #include<bits/stdc++.h>
- #define endl "\n"
- #define ll long long
- #define PI acos(-1.0)
- #define test cout<<"\n****\n"
- #define precise fixed(cout);cout<<setprecision(12)
- #define fast ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- using namespace std;
- vector<pair<ll,ll>> vec;
- int main(){
- fast;
- ll n;
- cin>>n;
- for(ll i=0;i<n;i++){
- ll g,d;
- cin>>g>>d;
- vec.push_back(make_pair(g,d));
- }
- sort(vec.rbegin(),vec.rend());
- bool slot[n];
- memset(slot, false,sizeof(slot));
- ll sum = 0;
- for (int i=0; i<n; i++)
- {
- for (int j=min(n, vec[i].second)-1; j>=0; j--)
- {
- if (slot[j]==false)
- {
- sum = sum + vec[i].first;
- slot[j] = true;
- break;
- }
- }
- }
- cout<<sum;
- return 0;
- }
Add Comment
Please, Sign In to add comment