Submission #1271903

#TimeUsernameProblemLanguageResultExecution timeMemory
1271903AgentPenginExhibition (JOI19_ho_t2)C++20
100 / 100
88 ms9436 KiB
/**
 *    author:  AgentPengin ( Độc cô cầu bại )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
#include<bits/stdc++.h>

#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)
#define int ll

using namespace std;

const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 1e5 + 5;

struct Pic {
	int s, v, id;
} p[MAXN];

int n, m, c[MAXN], pos[MAXN];
set<int> s;


signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (ifstream(NAME".inp")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
    cin >> n >> m;
    for (int i = 1;i <= n;i++) {
    	cin >> p[i].s >> p[i].v;
    	p[i].id = i;
    }
    for (int i = 1;i <= m;i++) cin >> c[i];
    sort(p + 1, p + n + 1, [&](const Pic& A, const Pic& B){
    	if (A.v == B.v) return A.s < B.s;
    	else return A.v < B.v;
    });
    for (int i = 1;i <= n;i++) {
    	pos[p[i].id] = i;
    }
    sort(p + 1, p + n + 1, [&](const Pic& A, const Pic& B){
    	return A.s < B.s;
    });
    sort(c + 1,c + m + 1);
    
    
    
    int ans = 0;
    for (int i = 1;i <= n;i++) s.insert(i);
    int cur = n + 1, ptr = n;
    for (int i = m;i >= 1;i--) {
    	while(c[i] < p[ptr].s && ptr > 0) {
    		if (s.find(pos[p[ptr].id]) != s.end()) {
    			s.erase(pos[p[ptr].id]);
    		}
    		ptr--;
    	}
    	auto it = s.lower_bound(cur);
    	if (it == s.begin()) break;
    	it--;
    	cur = *it;
    	ans++;
    	s.erase(it);
    }
    cout << ans;
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
// agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...