Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int n; cin >> n;
  11.     multiset<int> ti;
  12.     vector<int> ve;
  13.     for (int i = 0; i < n; ++i) {
  14.         char c; int w; cin >> c >> w;
  15.         if (c == 'T') ti.insert(w);
  16.         else ve.push_back(w);
  17.     }
  18.     ve.push_back(1000);
  19.     sort(ve.begin(), ve.end());
  20.     double t = 0; double v = 1;
  21.     double cnt = 1; double p = 0;
  22.     for (int i = 0; i < n; ++i) {
  23.         double time = t + (ve[i] - p) / v;
  24.         while (ti.size() > 0 && *ti.begin() <= time) {
  25.             p = p + v * (*ti.begin() - t); t = *ti.begin(); v = 1.0 / ++cnt;
  26.             time = t + (ve[i] - p) / v;
  27.             ti.erase(ti.begin());
  28.         }
  29.         t = time; v = 1.0 / ++cnt; p = ve[i];
  30.     }
  31.     cout << round(t);
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement