Advertisement
Guest User

C Innopolis

a guest
Nov 22nd, 2020
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.83 KB | None | 0 0
  1. //나는 가상 소녀들에게 큰 호감이 있습니다.
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <stdio.h>
  7. #include <cstring>
  8. #include <string>
  9. #include <cstdlib>
  10. #include <vector>
  11. #include <bitset>
  12. #include <map>
  13. #include <chrono>
  14. #include <functional>
  15. #include <unordered_set>
  16. #include <unordered_map>
  17. #include <numeric>
  18. #include <queue>
  19. #include <ctime>
  20. #include <stack>
  21. #include <set>
  22. #include <list>
  23. #include <deque>
  24. #include <iomanip>
  25. #include <sstream>
  26. #include <fstream>
  27. #include <stdarg.h>
  28. #include <utility>
  29.  
  30. using namespace std;
  31.  
  32. #define pb push_back
  33. #define mp make_pair
  34. #define ll long long
  35. #define ull unisgned long long
  36. #define ld long double
  37. #define all(a) a.begin(), a.end()
  38. #define SORT(a) sort(all(a))
  39. #define pii pair<int, int>
  40. #define tii triple<int, int, int>
  41. #define e 1e-7
  42. #define PI acos(-1)
  43. #define sz(a) (int)(a.size())
  44. #define inf 1e17
  45. #define vi vector<int>
  46. #define F first
  47. #define S second
  48. #define rng(x) for(int _ = 0; _ < (x); _++)
  49. #define rngi(i, x) for(int i = 0; i < (x); i++)
  50. #define rngsi(s, i, x) for(int i = (s); i <(x); i++)
  51. #define int long long
  52. #define problem "a"
  53.  
  54. template<typename A, typename B, typename C>
  55. struct triple {
  56.     A X;
  57.     B Y;
  58.     C Z;
  59.     triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
  60. };
  61. template<typename A, typename B, typename C>
  62. triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {
  63.     return triple<A, B, C>(a, b, c);
  64. }
  65. template<typename A, typename B, typename C>
  66. bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {
  67.     if (a.X != b.X)
  68.         return a.X < b.X;
  69.     if (a.Y != b.Y)
  70.         return a.Y < b.Y;
  71.     return a.Z < b.Z;
  72. }
  73. template<typename T, typename SS>
  74. ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {
  75.     ofs << "( " << p.F << " , " << p.S << " )";
  76.     return ofs;
  77. }
  78. template<typename T>
  79. void print(T a) {
  80.     for (auto i : a)
  81.         cout << i << ' ';
  82.     cout << '\n';
  83. }
  84. template<typename T>
  85. T max(T a, T b, T c) {
  86.     return max(a, max(b, c));
  87. }
  88. template<typename T>
  89. T min(T a, T b, T c) {
  90.     return min(a, min(b, c));
  91. }
  92. template<typename T, typename D>
  93. D min(T a) {
  94.     return *min_element(all(a));
  95. }
  96. template<typename T, typename D>
  97. D max(T a) {
  98.     return *max_element(all(a));
  99. }
  100. struct custom_hash {
  101.     static uint64_t splitmix64(uint64_t x) {
  102.         x += 0x9e3779b97f4a7c15;
  103.         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  104.         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  105.         return x ^ (x >> 31);
  106.     }
  107.  
  108.     size_t operator()(uint64_t x) const {
  109.         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  110.         return splitmix64(x + FIXED_RANDOM);
  111.     }
  112. };
  113. void solve() {
  114.     int n; cin >> n;
  115.     vector<vector<pii> > a(n);
  116.     rngi(i, n) {
  117.         vector<pii> b;
  118.         int m; cin >> m;
  119.         b.resize(m);
  120.         rngi(j, m) cin >> b[j].first >> b[j].second;
  121.         //rngi(j, m) b[j] = { rand() % 100, rand() % 10 };
  122.         SORT(b);
  123.         a[i].push_back({ 0,0 });
  124.         int c = 0;
  125.         rngi(j, m)
  126.             if (b[j].second > c) {
  127.                 a[i].push_back(b[j]);
  128.                 c = b[j].second;
  129.             }
  130.     }
  131.     vector<pii> c; c.push_back({ 0,0 });
  132.     rngi(i, n)
  133.         for (int j = 1; j < sz(a[i]); j++) c.push_back({ a[i][j].first, a[i][j].second - a[i][j - 1].second });
  134.     SORT(c);
  135.     rngi(i, sz(c) - 1) c[i + 1].second += c[i].second;
  136.     int q; cin >> q;
  137.     auto g = [&](int x) {
  138.         int v = upper_bound(all(c), pii{ x, (int)inf }) - c.begin();
  139.         return c[v - 1].second;
  140.     };
  141.     rng(q) {
  142.         int x; cin >> x;
  143.         int l = 1, r = 1e9 + 1;
  144.         while (r - l > 1) {
  145.             int m = l + r >> 1;
  146.             if (g(m) >= x) r = m; else l = m;
  147.         }
  148.         if (g(l) >= x) cout << l << '\n'; else if (r == 1e9 + 1) cout << "-1\n"; else  cout << r << '\n';
  149.     }
  150. };
  151. signed main()
  152. {
  153.     if (0) {
  154.         freopen(problem".in", "r", stdin);
  155.         freopen(problem".out", "w", stdout);
  156.     }
  157.     srand(time(NULL));
  158.     cin.tie(0);
  159.     cout.tie(0);
  160.     ios_base::sync_with_stdio(false);
  161.     int t = 1;// cin >> t;
  162.     rng(t) solve();
  163. }
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement