CEOI 2018 - Global Warming

Author: Albert Ye

Official Solutions Presentation

We can view the temperatures as an array . We want to decrement one contiguous interval by a value such that the length of the longest increasing subsequence is longest possible.

Subtasks 1-3: Brute Force

One key observation is that it is useless to subtract from any interval as opposed to just for any . Additionally, observe that it is optimal to simply subtract from the interval instead of some other .

An algorithm would involve brute forcing for all prefixes. Subtract from each interval for all and then find the LIS after each subtraction.

Subtask 4: One pass

Simply take the LIS of the array. Any algorithm to find the LIS will pass.

General Solution

For each , let be the length of the longest increasing subsequence ending at and be the length of the longest increasing subsequence starting at after is decremented. We can compute each by storing the length of the longest decreasing subsequence for each prefix of the reverse of the input array.

The final answer is .

Implementation

In the implementation is and is the variable on line .

C++

1#include <bits/stdc++.h>
2#define ll long long
3
4using namespace std;
5
6ll n, x, v[200005], dp[200005];
7
8int main()
9{
10 cin >> n >> x;

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on CEOI 2018 - Global Warming!