NOI.sg - 2019 - Feast
Author: Dong Liu
Time Complexity: .
C++
Like a normal Aliens Trick problem, we're going to binary search on the maximum where the number of subarrays used is .
Now, for a given , we're going to calculate the number of people in an optimal food arrangement such that we subtract for every person.
Let's have represent the maximum sum of satisfaction of an arrangement of the first plates, given that implies whether plate is being used. Let represent the number of people used in an optimal arrangement of .
For our transitions, we have
and
because we either begin a new subarray or we continue an existing subarray.
Since calculating takes time, and we're binary searching on the range , the time complexity is .
#include <bits/stdc++.h>using namespace std;const int N = 300000;const long long INF = (long long)300000 * 1000000000;const long double EPS = 1e-3;int n, k, a[N + 1];pair<long double, int> dp[N + 1][2];
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!