-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path10131-Is Bigger Smarter?.cpp
45 lines (43 loc) · 1.24 KB
/
10131-Is Bigger Smarter?.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int w,s;
int i=1;
vector<tuple<int,int,int>> elephants;
while(scanf("%d %d",&w,&s)!=EOF){
elephants.push_back(make_tuple(w,s,i++));
}
auto cmp = [](const tuple<int,int,int>& a,const tuple<int,int,int>& b){
if(get<0>(a) != get<0>(b)) return get<0>(a) < get<0>(b);
return get<1>(a) > get<1>(b);
};
sort(elephants.begin(),elephants.end(),cmp);
vector<int> dp;
vector<int> parent;
int bestIdx = 0, best = 0;
for(int i=0;i<elephants.size();i++){
int prev = -1, longest=0;
for(int j=0;j<i;j++){
if(get<0>(elephants[i]) > get<0>(elephants[j]) &&
get<1>(elephants[i]) < get<1>(elephants[j]) &&
dp[j] > longest){
longest = dp[j];
prev = j;
}
}
parent.push_back(prev);
dp.push_back(longest+1);
if(dp.back() > best){
best = dp.back();
bestIdx = i;
}
}
stack<int> res;
while(bestIdx != -1){
res.push(get<2>(elephants[bestIdx]));
bestIdx = parent[bestIdx];
}
printf("%d\n",best);
while(!res.empty()) printf("%d\n",res.top()), res.pop();
}