Sunjaree

Job Scheduling / SPOJ-Milk Scheduling Solution

Oct 13th, 2020 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. /*    problem link:
  2.       https://www.spoj.com/problems/MSCHED/en/    */
  3.  
  4. #include<bits/stdc++.h>
  5. #define endl  "\n"
  6. #define ll long long
  7. #define PI acos(-1.0)
  8. #define test cout<<"\n****\n"
  9. #define precise fixed(cout);cout<<setprecision(12)
  10. #define fast  ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  11. using  namespace  std;
  12.  
  13. vector<pair<ll,ll>> vec;
  14. int main(){
  15.  
  16.     fast;
  17.     ll n;
  18.     cin>>n;
  19.  
  20.     for(ll i=0;i<n;i++){
  21.         ll g,d;
  22.         cin>>g>>d;
  23.         vec.push_back(make_pair(g,d));
  24.     }
  25.     sort(vec.rbegin(),vec.rend());
  26.  
  27.     bool slot[n];
  28.     memset(slot, false,sizeof(slot));
  29.  
  30.     ll sum = 0;
  31.     for (int i=0; i<n; i++)
  32.     {
  33.         for (int j=min(n, vec[i].second)-1; j>=0; j--)
  34.         {
  35.             if (slot[j]==false)
  36.             {
  37.                 sum = sum + vec[i].first;
  38.                 slot[j] = true;
  39.                 break;
  40.             }
  41.         }
  42.     }
  43.     cout<<sum;
  44.  
  45.     return 0;
  46. }
  47.  
Add Comment
Please, Sign In to add comment