fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define pb push_back
  6. #define lcm(a,b) ll lcm_function(ll a , ll b) return (a*b)/__gcd(a,b);
  7.  
  8. void solve ()
  9. {
  10.  
  11. int n,max_val=0;
  12. cin >> n;
  13.  
  14. vector<pair<int,int>> vec;
  15. for(int i=0;i<n;i++)
  16. {
  17. int a,b,c;
  18. cin >> a >> b >> c;
  19. vec.pb({c,b});
  20. max_val = max(b,max_val);
  21. }
  22.  
  23. sort(vec.begin(), vec.end(),[](pair<int,int> p1, pair<int,int> p2){return p1.first > p2.first;});
  24.  
  25. vector<int> job_sequence(max_val,0);
  26.  
  27. int j=0,profit=0,terms=0;
  28.  
  29. while(j<vec.size())
  30. {
  31. if(job_sequence[vec[j].second -1]==0) {
  32. terms++;
  33. job_sequence[vec[j].second -1]=vec[j].first;
  34. profit+=job_sequence[vec[j].second-1];
  35. }
  36. else{
  37. int t = vec[j].second -2;
  38. while(t>=0)
  39. {
  40. if(job_sequence[t]==0) {
  41. terms++;
  42. job_sequence[t]=vec[j].first;
  43. profit+=job_sequence[t];
  44. break;
  45. }
  46. t--;
  47. }
  48. }
  49. j++;
  50. }
  51. cout<<terms<<" "<<profit<<"\n";
  52. }
  53.  
  54. int main()
  55. {
  56. ios_base::sync_with_stdio(false);
  57. cin.tie(NULL);
  58. cout.tie(NULL);
  59.  
  60. solve();
  61.  
  62.  
  63. }
  64.  
Runtime error #stdin #stdout 3.67s 2095860KB
stdin
Standard input is empty
stdout
Standard output is empty