1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| /**************************************************************
Problem: 1510
User: abcdabcd987
Language: C++
Result: Accepted
Time:500 ms
Memory:2584 kb
****************************************************************/
#include <iostream>
#include <stack>
using namespace std;
int n,m;
bool flag;
stack<int> S;
int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for (int i=1,last=1000000001,x;i<=n;++i) {
cin>>x;
x=min(last,x);
S.push(x);
last=min(last,x);
}
flag=true;
for (int i=1,x;i<=m && flag;++i) {
cin>>x;
while (!S.empty() && S.top()<x) S.pop();
flag&=!S.empty();
S.pop();
}
if (!flag)
cout<<0;
else
cout<<S.size()+1;
}
|