Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #define l first
- #define r second
- #define int int64_t
- #define double long double
- using namespace std;
- using namespace __gnu_pbds;
- std::mt19937_64 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
- std::uniform_real_distribution<double> rnd_double(0, 1);
- int nextInt(int r) { // [0; R)
- return rnd() % r;
- }
- int nextInt(int l, int r) { // [L; R)
- return l + rnd() % (r - l);
- }
- double nextDouble() { // [0; 1]
- return rnd_double(rnd);
- }
- double nextDouble(double r) { // [0; R]
- return r * nextDouble();
- }
- double nextDouble(double l, double r) { // [L; R]
- return l + (r - l) * nextDouble();
- }
- template <typename T>
- using Orset = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag,
- __gnu_pbds::tree_order_statistics_node_update>;
- template <typename T>
- using Ormultiset =
- __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less_equal<T>, __gnu_pbds::rb_tree_tag,
- __gnu_pbds::tree_order_statistics_node_update>;
- void runSolve() {
- int n, m;
- cin >> n >> m;
- vector<pair<int, int>> queries;
- while (n--) {
- int l, r;
- cin >> l >> r;
- queries.emplace_back(l, 1);
- queries.emplace_back(r, 3);
- }
- while (m--) {
- int x;
- cin >> x;
- queries.emplace_back(x, 2);
- }
- sort(queries.begin(), queries.end());
- int cnt = 0;
- pair<int, int> ans = {-1, -1};
- for (auto [x, type] : queries) {
- if (type == 1) {
- cnt++;
- } else if (type == 2) {
- if (ans.second < cnt) {
- ans = {x, cnt};
- }
- } else {
- cnt--;
- }
- }
- cout << ans.first << ' ' << ans.second << '\n';
- }
- int32_t main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int t = 1;
- // cin >> t;
- while (t--) {
- runSolve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment