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>
#ifndef ARTHUR_LOCAL
#include "teams.h"
#endif
using namespace std;
const int MAXN=100001;
int n;
vector<pair<int,int>> I;
bool comp(pair<int,int> a, pair<int,int> b)
{
if(a.second != b.second) return a.second < b.second;
return a.first < b.first;
}
void init(int N, int a[], int b[])
{
n=N;
for(int i=0; i<n; i++)
{
I.push_back({a[i],b[i]});
}
sort(I.begin(),I.end());
}
int can(int m, int K[])
{
int cur_ind = 0;
sort(K,K+m); // ???
priority_queue<pair<int,int>> PQ; // increasing order of second coordinate
for(int i=0; i<m; i++)
{
//cout << K[i] << endl;
while(cur_ind < n && I[cur_ind].first <= K[i])
{
//cout << "ADDING " << I[cur_ind].first << " " << I[cur_ind].second << endl;
PQ.push({-I[cur_ind].second,I[cur_ind].first});
cur_ind++;
}
// cout << PQ.size() << endl;
while(!PQ.empty() && -PQ.top().first < K[i])
{
//cout << "REMOVING " << PQ.top().second << " " << -PQ.top().first << endl;
PQ.pop();
}
for(int dot=1; dot<=K[i]; dot++)
{
if(PQ.empty()) return 0;
PQ.pop();
//cout << "PILLY POPPED" << endl;
while(!PQ.empty() && -PQ.top().first < K[i])
{
//cout << "ALSO REMOVING " << PQ.top().second << " " << -PQ.top().first << endl;
PQ.pop();
}
}
}
return 1;
}
#ifdef ARTHUR_LOCAL
int A[4];
int B[4];
int K1[2];
int K2[2];
int main()
{
A[0]=1;
A[1]=2;
A[2]=2;
A[3]=2;
B[0]=2;
B[1]=3;
B[2]=3;
B[3]=4;
init(4,A,B);
K1[0]=3;
K1[1]=1;
cout << can(2,K1) << endl;
K2[0]=1;
K2[1]=1;
cout << can(2,K2) << endl;
}
#endif
# | 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... |