Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #define ull unsigned long long
- #define ll long long
- using namespace std;
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- vector<int> d(n, 1);
- vector<int> p(n, -1);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < i; j++) {
- if (a[j] >= a[i]) {
- if (d[i] < d[j] + 1) {
- p[i] = j;
- d[i] = d[j] + 1;
- }
- }
- }
- }
- int ans = 0;
- for (int i = 0; i < n; i++) {
- if (d[i] > d[ans]) {
- ans = i;
- }
- }
- if (d[ans] <= 1) {
- cout << 0;
- return 0;
- }
- vector<int> r;
- cout << d[ans] << endl;
- while (p[ans] != -1) {
- r.push_back(ans + 1);
- ans = p[ans];
- }
- r.push_back(ans + 1);
- for (int i = r.size() - 1; i >= 0; i--) {
- cout << r[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment