#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MN = 200010;
int N;
vector<int> V[MN], X[MN];
priority_queue<int> freeV;
multiset<int> freeX;
int la[MN];
int main() {
std::ios::sync_with_stdio(false);
cin >> N;
for(int i = 0; i < N; i++) {
int a, b; cin >> a >> b;
V[--a].push_back(b);
}
for(int i = 0; i < N; i++) {
int c, d; cin >> c >> d;
X[--c].push_back(d);
}
int ans = 0;
for(int i = 0; i < N; i++) {
sort(V[i].begin(), V[i].end());
sort(X[i].begin(), X[i].end());
vector<int> chk(V[i].size(), 0);
vector<int> tmp;
int pos = (int)X[i].size() - 1;
for(int j = (int)V[i].size() - 1; j >= 0; j--) {
if(pos >= 0 && V[i][j] <= X[i][pos]) {
pos--;
continue;
}
freeV.push(V[i][j]);
chk[j] = 1;
}
for(int j = 0; j < V[i].size(); j++) if(!chk[j]) tmp.push_back(V[i][j]);
V[i] = tmp;
if(V[i].size() == 0) {
for(int j = 0; j < X[i].size(); j++) {
freeX.insert(X[i][j]);
}
la[i] = -1;
continue;
}
chk = vector<int>(X[i].size(), 0);
pos = 0;
for(int j = 0; j < V[i].size(); j++) {
while(pos < X[i].size() && X[i][pos] < V[i][j]) pos++;
chk[pos] = 1;
pos++;
}
tmp.clear();
for(int j = 0; j < X[i].size(); j++) {
if(chk[j]) tmp.push_back(X[i][j]);
else freeX.insert(X[i][j]);
}
X[i] = tmp;
la[i] = (int)V[i].size() - 1;
}
ans += freeV.size();
while(!freeV.empty()) {
int v = freeV.top(); freeV.pop();
auto it = freeX.lower_bound(v);
if(it != freeX.end()) {
freeX.erase(it);
continue;
}
ans++;
int mn = 1e9;
int p = -1;
for(int i = 0; i < N; i++) {
while(la[i] >= 0 && V[i][ la[i] ] >= v) la[i]--;
if(la[i] >= 0 && X[i][ la[i] ] >= v) {
int tmp = 1e9;
for(int j = la[i]; j >= 0; j--) {
if(j == 0 || X[i][j - 1] < V[i][j]) {
tmp = V[i][j];
break;
}
}
if(mn > tmp) {
mn = tmp;
p = i;
}
}
}
for(int i = la[p]; i >= 0; i--) {
if(i == 0 || X[p][i - 1] < V[p][i]) {
freeV.push(V[p][i]);
V[p][i] = v;
break;
}
else swap(v, V[p][i]);
}
}
cout << ans;
}
Compilation message
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:45:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < V[i].size(); j++) if(!chk[j]) tmp.push_back(V[i][j]);
~~^~~~~~~~~~~~~
worst_reporter2.cpp:49:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < X[i].size(); j++) {
~~^~~~~~~~~~~~~
worst_reporter2.cpp:59:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < V[i].size(); j++) {
~~^~~~~~~~~~~~~
worst_reporter2.cpp:60:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(pos < X[i].size() && X[i][pos] < V[i][j]) pos++;
~~~~^~~~~~~~~~~~~
worst_reporter2.cpp:66:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < X[i].size(); j++) {
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9724 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9720 KB |
Output is correct |
11 |
Correct |
10 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9724 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9720 KB |
Output is correct |
11 |
Correct |
10 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9848 KB |
Output is correct |
13 |
Correct |
10 ms |
9768 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9692 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9720 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9724 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9720 KB |
Output is correct |
11 |
Correct |
10 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9848 KB |
Output is correct |
13 |
Correct |
10 ms |
9768 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9692 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9720 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9848 KB |
Output is correct |
23 |
Correct |
30 ms |
10232 KB |
Output is correct |
24 |
Correct |
30 ms |
10360 KB |
Output is correct |
25 |
Correct |
30 ms |
10232 KB |
Output is correct |
26 |
Correct |
36 ms |
10204 KB |
Output is correct |
27 |
Correct |
15 ms |
10232 KB |
Output is correct |
28 |
Correct |
14 ms |
9848 KB |
Output is correct |
29 |
Correct |
20 ms |
9976 KB |
Output is correct |
30 |
Correct |
22 ms |
9976 KB |
Output is correct |
31 |
Correct |
34 ms |
9976 KB |
Output is correct |
32 |
Correct |
13 ms |
9976 KB |
Output is correct |
33 |
Correct |
14 ms |
9848 KB |
Output is correct |
34 |
Correct |
16 ms |
9976 KB |
Output is correct |
35 |
Correct |
17 ms |
9980 KB |
Output is correct |
36 |
Correct |
32 ms |
9948 KB |
Output is correct |
37 |
Correct |
13 ms |
9976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9720 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
10 ms |
9720 KB |
Output is correct |
5 |
Correct |
10 ms |
9720 KB |
Output is correct |
6 |
Correct |
10 ms |
9724 KB |
Output is correct |
7 |
Correct |
10 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
10 ms |
9720 KB |
Output is correct |
11 |
Correct |
10 ms |
9720 KB |
Output is correct |
12 |
Correct |
11 ms |
9848 KB |
Output is correct |
13 |
Correct |
10 ms |
9768 KB |
Output is correct |
14 |
Correct |
10 ms |
9720 KB |
Output is correct |
15 |
Correct |
10 ms |
9720 KB |
Output is correct |
16 |
Correct |
10 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
11 ms |
9692 KB |
Output is correct |
19 |
Correct |
10 ms |
9720 KB |
Output is correct |
20 |
Correct |
10 ms |
9720 KB |
Output is correct |
21 |
Correct |
10 ms |
9720 KB |
Output is correct |
22 |
Correct |
11 ms |
9848 KB |
Output is correct |
23 |
Correct |
30 ms |
10232 KB |
Output is correct |
24 |
Correct |
30 ms |
10360 KB |
Output is correct |
25 |
Correct |
30 ms |
10232 KB |
Output is correct |
26 |
Correct |
36 ms |
10204 KB |
Output is correct |
27 |
Correct |
15 ms |
10232 KB |
Output is correct |
28 |
Correct |
14 ms |
9848 KB |
Output is correct |
29 |
Correct |
20 ms |
9976 KB |
Output is correct |
30 |
Correct |
22 ms |
9976 KB |
Output is correct |
31 |
Correct |
34 ms |
9976 KB |
Output is correct |
32 |
Correct |
13 ms |
9976 KB |
Output is correct |
33 |
Correct |
14 ms |
9848 KB |
Output is correct |
34 |
Correct |
16 ms |
9976 KB |
Output is correct |
35 |
Correct |
17 ms |
9980 KB |
Output is correct |
36 |
Correct |
32 ms |
9948 KB |
Output is correct |
37 |
Correct |
13 ms |
9976 KB |
Output is correct |
38 |
Execution timed out |
2040 ms |
32036 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |