This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "teams.h"
const ll siz = 500005;
ll a[siz],b[siz];
ll n;
void init(int N, int A[], int B[]){
n = N;
f(i,0,n){
a[i] = A[i];
b[i] = B[i];
}
}
int can(int M, int K[]) {
vector<ii>arr;
set<iii>ex;
ll pos = 0;
f(i,0,n){
arr.pb(ii(a[i],b[i]));
}
sort(K,K+M);
sort(all(arr));
bool ok = true;
f(i,0,M){
while(pos < n && arr[pos].F <= K[i]){
ex.insert(iii(ii(arr[pos].S,arr[pos].F),pos));
pos++;
}
while(!ex.empty()){
auto it = ex.begin();
if((*it).F.F < K[i]){
ex.erase((*it));
}
else{
break;
}
}
if(ex.size() < K[i]){
ok = false;
break;
}
else{
f(j,0,K[i]){
auto it = ex.begin();
ex.erase((*it));
}
}
}
return ok;
}
/*
int main() {
int N;
cin>>N;
int *A = (int*)malloc(sizeof(int)*(unsigned int)N);
int *B = (int*)malloc(sizeof(int)*(unsigned int)N);
for (int i = 0; i < N; ++i) {
cin>>A[i]>>B[i];
}
init(N, A, B);
int Q;
cin>>Q;
for (int i = 0; i < Q; ++i) {
int M;
cin>>M;
int *K = (int*)malloc(sizeof(int)*(unsigned int)M);
for (int j = 0; j < M; ++j) {
cin>>K[j];
}
printf("%d\n", can(M, K));
}
return 0;
}
*/
/*
4
2 4
1 2
2 3
2 3
2
2 1 3
2 1 1
*/
Compilation message (stderr)
teams.cpp: In function 'int can(int, int*)':
teams.cpp:60:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
60 | if(ex.size() < K[i]){
| ~~~~~~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |