Advertisement
SorahISA

4-agojis-equal-day-trip

Apr 10th, 2023
758
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #pragma GCC optimize("Ofast", "unroll-loops")
  2. // #pragma GCC target("avx")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define int int64_t
  7. #define double __float80
  8. using pii = pair<int, int>;
  9. template <typename T> using Prior = std::priority_queue<T>;
  10. template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
  11.  
  12. #define X first
  13. #define Y second
  14. #define eb emplace_back
  15. #define ef emplace_front
  16. #define ee emplace
  17. #define pb pop_back
  18. #define pf pop_front
  19. #define ALL(x) begin(x), end(x)
  20. #define RALL(x) rbegin(x), rend(x)
  21. #define SZ(x) ((int)(x).size())
  22.  
  23. #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
  24. template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
  25. template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
  26.  
  27. template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
  28. template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
  29.  
  30. const int INF = LLONG_MAX >> 2;
  31.  
  32. void solve() {
  33.     int N; cin >> N;
  34.    
  35.     vector<pair<int, vector<pii>>> city;
  36.     int city_tok = 0;
  37.     map<string, int> city_id;
  38.     for (int i = 0; i < N; ++i) {
  39.         string name; cin >> name;
  40.         int days, cost; cin >> days >> cost;
  41.         if (!city_id.count(name)) city_id[name] = city_tok++, city.eb(0, 0);
  42.         city[city_id[name]].X += days;
  43.         city[city_id[name]].Y.eb(cost, days);
  44.     }
  45.     sort(ALL(city), [](const auto &a, const auto &b) {return a.X > b.X;});
  46.     for (auto &c : city) sort(ALL(c.Y));
  47.     N = SZ(city);
  48.    
  49.     int max_day = 0, min_cost = INF;
  50.     for (int i = 0; i < N; ++i) chmax(max_day, (i+1) * city[i].X);
  51.    
  52.     for (int i = 0; i < N; ++i) {
  53.         if (max_day != (i+1) * city[i].X) continue;
  54.         // cout << "[" << i << "]\n";
  55.         int cost = 0;
  56.         for (int j = 0; j <= i; ++j) {
  57.             int D_left = city[i].X;
  58.             for (pii &plan : city[j].Y) {
  59.                 int C = plan.X, D = plan.Y;
  60.                 cost += C * min(D, D_left);
  61.                 D_left -= D;
  62.                 if (D_left <= 0) break;
  63.             }
  64.         }
  65.         chmin(min_cost, cost);
  66.     }
  67.     cout << max_day << " " << min_cost << "\n";
  68. }
  69.  
  70. int32_t main() {
  71.     fastIO();
  72.    
  73.     int t = 1; // cin >> t;
  74.     for (int _ = 1; _ <= t; ++_) {
  75.         solve();
  76.     }
  77.    
  78.     return 0;
  79. }
  80.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement