// earth cooling
#include <bits/stdc++.h>
using namespace std;
int main() {
int dayc, limit;
cin>>dayc>>limit;
int days[dayc];
for (int i = 0; i < dayc; ++i) {
cin>>days[i];
}
if (limit <= 50) {
int leftBound, rightBound, modifier, out = 0;
for (leftBound = 0; leftBound < dayc; ++leftBound) {
for (rightBound = leftBound + 1; rightBound <= dayc; ++rightBound) {
for (modifier = 0; modifier < limit; ++modifier) {
vector<int> LISs;
for (int i = 0; i < dayc; ++i) {
int l = -1, r = LISs.size();
while (r - l > 1) {
int m = (r+l)/2;
if (LISs[m] >= days[i] + (i < rightBound && i > leftBound) * modifier) {
r = m;
} else {
l = m;
}
}
if (r == LISs.size()) {
LISs.push_back(days[i] + (i < rightBound && i > leftBound) * modifier);
} else {
LISs[r] = min(LISs[r], days[i] + (i < rightBound && i > leftBound) * modifier);
}
}
out = max(out, int(LISs.size()));
}
}
}
cout<<out;
// } else if (days <= 1000) {
} else {
int LISs[2][dayc];
int end1 = 0;
for (int i=0; i<dayc; ++i) {
LISs[0][i] = INT_MAX;
LISs[1][i] = INT_MAX;
}
for (int i=0; i < dayc; ++i) {
if (end1 > 0) {
int l = -1, r = end1;
while (r - l > 1) {
int m = (r+l)/2;
if (LISs[1][m] >= days[i]) {
r = m;
} else {
l = m;
}
}
LISs[1][r] = min(LISs[1][r], days[i]);
l = -1, r = end1;
while (r - l > 1) {
int m = (r+l)/2;
if (LISs[0][m] >= days[i]) {
r = m;
} else {
l = m;
}
}
if (LISs[0][r] == -1 || LISs[1][r]) ++end1;
LISs[0][r] = min(LISs[0][r], days[i]);
LISs[1][r] = min(LISs[1][r], days[i]);
LISs[1][end1+1] = min(LISs[1][end1+1], days[i]);
} else {
end1 = 1;
LISs[0][0] = days[i];
LISs[1][0] = days[i];
}
}
cout<<end1;
}
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:28:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (r == LISs.size()) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
388 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
388 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
388 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2052 ms |
1116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2041 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
1360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
388 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |