Advertisement
artemgf

Очередь на зачёт

Nov 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <map>
  8. #include <queue>
  9. #include <set>
  10. #include <stack>
  11.  
  12. using namespace std;
  13.  
  14. typedef long long ll;
  15.  
  16. struct pep
  17. {
  18.     ll t1, t2, t3;
  19. };
  20.  
  21. bool d(pep p1, pep p2)
  22. {
  23.     return p1.t1 < p2.t1;
  24. }
  25.  
  26. int main()
  27. {
  28.     ll n;
  29.     cin >> n;
  30.     ll mintime=-1000, alltime=0;
  31.     vector<pep>all;
  32.     pep prom;
  33.     for (int i = 1; i <= n; i++)
  34.     {
  35.         cin >> prom.t1 >> prom.t2 >> prom.t3;
  36.         all.push_back(prom);
  37.     }
  38.  
  39.     sort(all.begin(), all.end(), d);
  40.  
  41.     for (int i = 0; i < all.size(); i++)
  42.     {
  43.         if (all[i].t1 > alltime)
  44.             alltime = all[i].t1;
  45.         alltime += all[i].t2;
  46.         ll badtime = alltime - all[i].t3;
  47.         if (mintime < badtime)
  48.             mintime = badtime;
  49.     }
  50.  
  51.     if (mintime >= 0)
  52.         cout << mintime;
  53.     else
  54.         cout << 0;
  55.     _getch();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement