-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_1_Increasing_Subsequence_easy_version.cpp
More file actions
78 lines (70 loc) · 1.41 KB
/
C_1_Increasing_Subsequence_easy_version.cpp
File metadata and controls
78 lines (70 loc) · 1.41 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstring>
using ll = long long;
using ull = unsigned long long;
using lld = long double;
#define GREETINGS_FROM_LOS_POCATOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
int main()
{
GREETINGS_FROM_LOS_POCATOS
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
string result = "";
int prev = 0;
int left = 0, right = n - 1;
while (left <= right)
{
if (v[left] > prev && v[right] > prev)
{
if (v[left] < v[right])
{
result += 'L';
prev = v[left];
left++;
}
else
{
result += 'R';
prev = v[right];
right--;
}
}
else if (v[left] > prev)
{
result += 'L';
prev = v[left];
left++;
}
else if (v[right] > prev)
{
result += 'R';
prev = v[right];
right--;
}
else
{
break;
}
}
cout << result.size() << endl;
cout << result << endl;
return 0;
}