Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define reset(x) memset(x, 0,sizeof(x))
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define N 100005
- #define remain(x) if (x > MOD) x -= MOD
- #define ii pair<int, int>
- #define vi vector<int>
- #define vii vector< ii >
- #define bit(x, i) (((x) >> (i)) & 1)
- #define Task "test"
- #define int long long
- using namespace std;
- typedef long double ld;
- int n, a[N];
- void readfile()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- if (fopen(Task".inp","r"))
- {
- freopen(Task".inp","r",stdin);
- //freopen(Task".out","w",stdout);
- }
- cin >> n;
- for(int i=1; i<=n; i++) cin >> a[i];
- }
- int dp[N];
- int trace[N];
- int pos, Max = 0;
- void truyvet()
- {
- int s = pos;
- stack<int> st;
- while (s != 0)
- {
- st.push(s);
- s = trace[s];
- }
- while (st.size())
- {
- cout << st.top() << ' ';
- st.pop();
- }
- }
- void proc()
- {
- memset(trace, -1, sizeof trace);
- for(int i=1; i<=n; i++)
- {
- dp[i] = 0;
- for(int j=0; j<i; j++){
- if (a[j] <= a[i]){
- if (dp[i] <= dp[j] + 1)
- {
- dp[i] = dp[j] + 1;
- trace[i] = j;
- }
- }
- }
- }
- for(int i=1; i<=n; i++)
- {
- if (dp[i] > Max)
- {
- Max = dp[i];
- pos = i;
- }
- }
- cout << Max << '\n';
- truyvet();
- }
- signed main()
- {
- readfile();
- proc();
- return 0;
- }
Add Comment
Please, Sign In to add comment