Submission #332731

#TimeUsernameProblemLanguageResultExecution timeMemory
332731limabeansExhibition (JOI19_ho_t2)C++17
0 / 100
1 ms364 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...