Submission #332731

# Submission time Handle Problem Language Result Execution time Memory
332731 2020-12-03T04:54:56 Z limabeans Exhibition (JOI19_ho_t2) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;





const int inf = 2e9;




void print(vector<int> a, int n) {
    for (int i=0; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);


    
    int n, m;
    cin>>n>>m;
    
    vector<pair<int,int>> a(n);
    
    for (int i=0; i<n; i++) {
	cin>>a[i].first>>a[i].second;
    }

    vector<int> w(m);
    for (int i=0; i<m; i++) {
	cin>>w[i];
    }

    sort(w.begin(),w.end());
    vector<vector<int>> items(m);



    for (auto p: a) {
	int size = p.first;
	int value = p.second;
	int idx = std::lower_bound(w.begin(),w.end(),size)-w.begin();
	if (idx==m) {
	    continue;
	}
	items[idx].push_back(value);
    }




    

    vector<int> dp(m+10, -inf); //dp[i]: min value of i+1 items
    int mx = -1;


    auto insert = [&](int x, int ub) {
	int lo = -1;
	int hi = m-1;
	while (hi-lo>1) {
	    int mid=(lo+hi)/2;
	    if (dp[mid]<x) { // leftmost smaller
		hi = mid;
	    } else {
		lo = mid;
	    }
	}

	if (hi<=ub) {
	    dp[hi] = x;
	    mx = max(mx, hi);
	}

	//print(dp, m);
    };

    int ans = 0;
    for (int i=m-1; i>=0; i--) {
	sort(items[i].rbegin(),items[i].rend());
	for (int val: items[i]) {
	    insert(val, m-i-1);
	}
	ans = max(ans, mx+1);
    }


    cout<<ans<<endl;    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -