-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10131.cc
More file actions
58 lines (53 loc) · 1.01 KB
/
10131.cc
File metadata and controls
58 lines (53 loc) · 1.01 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int w1,s1;
vector <int> w;
vector <int> s;
int n=0;
while(cin>>w1)
{
cin>>s1;
w.push_back(w1);
s.push_back(s1);
n++;
}
vector <int> dp(n,1);
vector <int> prev(n,-1);
for(int i = 0; i <n; ++i)
{
prev[i] = i;
for(int j = i-1; j >= 0 ; --j)
{
if(dp[j] + 1 > dp[i] && w[i] > w[j] && s[i] < s[j])
{
dp[i] = dp[j]+1;
prev[i] = j;
}
}
}
int big = -1;
int ind = 0;
for(int i =0 ; i< n; ++i)
{
if(dp[i] > big)
{
big = dp[i];
ind = i;
}
}
vector <int> ans;
cout<<big<<endl;
while(prev[ind] != ind)
{
ans.push_back(ind);
ind = prev[ind];
}
ans.push_back(ind);
for(int i = int(ans.size())-1; i >= 0 ; --i)
cout<<ans[i]+1<<endl;
return 0;
}