Submission #367345

# Submission time Handle Problem Language Result Execution time Memory
367345 2021-02-16T23:00:02 Z piddddgy Exhibition (JOI19_ho_t2) C++11
100 / 100
222 ms 4696 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// #define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ld long double
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
    

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 mt(seed);

const int maxn = 100500;
    
int n, m;
pii a[maxn];
int c[maxn];
    
int ans = 0;

// take the x biggest frames
bool go(int upto) {
    priority_queue<int> pq;
    for(int i = 1; i <= upto; i++) {
        pq.push(-c[i]);
    }

    int loc = 0;
    int lst = -1e18;
    for(int i = 1; i <= n; i++) {
        if(pq.empty()) break;

        int x = -pq.top();

        if(a[i].se <= x) {
            loc++;
            pq.pop();
        }
    }

    ans = max(ans, loc);
    return loc == upto;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> m;
    
    // .fi = value, .se = size
    for(int i = 1; i <= n; i++) {
        cin >> a[i].se >> a[i].fi;
    }
    
    for(int i = 1; i <= m; i++) cin >> c[i];

    sort(a+1, a+n+1);

    sort(c+1, c+m+1);
    reverse(c+1, c+m+1);

    // for(int i = 1; i <= m; i++) go(i);

    int l = 1, r = m;
    while(l <= r) {
        int mid = (l+r)/2;

        if(go(mid)) {
            l = mid+1;
        } else {
            r = mid-1;
        }
    }


    cout << ans << endl;
}
    
/*
    
sort by value then by size
you will always take the biggest frames


    
Did you read the bounds?
Did you make typos?
Are there edge cases (N=1?)
Are array sizes proper?
Integer overflow?
DS reset properly between test cases?
Is using long longs causing TLE?
Are you using floating points?
*/

Compilation message

joi2019_ho_t2.cpp: In function 'bool go(long long int)':
joi2019_ho_t2.cpp:37:9: warning: unused variable 'lst' [-Wunused-variable]
   37 |     int lst = -1e18;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 209 ms 4640 KB Output is correct
39 Correct 178 ms 4580 KB Output is correct
40 Correct 161 ms 4576 KB Output is correct
41 Correct 222 ms 4672 KB Output is correct
42 Correct 56 ms 3332 KB Output is correct
43 Correct 59 ms 3440 KB Output is correct
44 Correct 122 ms 4196 KB Output is correct
45 Correct 221 ms 4576 KB Output is correct
46 Correct 175 ms 4596 KB Output is correct
47 Correct 161 ms 4100 KB Output is correct
48 Correct 139 ms 4256 KB Output is correct
49 Correct 158 ms 3884 KB Output is correct
50 Correct 138 ms 3880 KB Output is correct
51 Correct 57 ms 3440 KB Output is correct
52 Correct 57 ms 3312 KB Output is correct
53 Correct 57 ms 3312 KB Output is correct
54 Correct 121 ms 4696 KB Output is correct
55 Correct 188 ms 4576 KB Output is correct
56 Correct 31 ms 1900 KB Output is correct
57 Correct 23 ms 1776 KB Output is correct
58 Correct 36 ms 2028 KB Output is correct
59 Correct 32 ms 1900 KB Output is correct
60 Correct 23 ms 1776 KB Output is correct
61 Correct 77 ms 2532 KB Output is correct
62 Correct 149 ms 4252 KB Output is correct
63 Correct 150 ms 4252 KB Output is correct
64 Correct 161 ms 4252 KB Output is correct
65 Correct 156 ms 4252 KB Output is correct
66 Correct 162 ms 4252 KB Output is correct
67 Correct 155 ms 4252 KB Output is correct
68 Correct 149 ms 4252 KB Output is correct
69 Correct 163 ms 4252 KB Output is correct
70 Correct 146 ms 4252 KB Output is correct
71 Correct 146 ms 4332 KB Output is correct
72 Correct 155 ms 4252 KB Output is correct
73 Correct 131 ms 4252 KB Output is correct