Submission #217891

# Submission time Handle Problem Language Result Execution time Memory
217891 2020-03-31T07:51:51 Z quocnguyen1012 Feast (NOI19_feast) C++14
12 / 100
190 ms 13944 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 3e5 + 5;

int a[maxn], N, K;
pair<ll, int> f[maxn][2];

pair<ll, int> best(pair<ll, int> a, pair<ll, int> b)
{
  if(a.fi == b.fi) return a.se < b.se ? a : b;
  return a.fi > b.fi ? a : b;
}

pair<ll, int> operator - (pair<ll, int> a, ll x)
{
  return mp(a.fi - x, a.se + 1);
}

pair<ll, int> operator + (pair<ll, int> a, ll x)
{
  return mp(a.fi + x, a.se);
}

pair<ll, int> solve(int cost)
{
  for(int i = 1; i <= N; ++i){
    f[i][0] = best(f[i - 1][0], f[i - 1][1] - cost);
    f[i][1] = best(f[i - 1][0], f[i - 1][1]) + a[i];
  }
  return best(f[N][0], f[N][1] - cost);
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> K;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
  }
  ll l = 0, r  = 1e9, mid;
  while(l <= r){
    mid = (l + r) / 2;
    if(solve(mid).se > K) l = mid + 1;
    else r = mid  - 1;
  }
  cout << solve(l).fi + l * K;
}
# Verdict Execution time Memory Grader output
1 Correct 174 ms 13560 KB Output is correct
2 Correct 178 ms 13560 KB Output is correct
3 Correct 182 ms 13944 KB Output is correct
4 Correct 181 ms 13688 KB Output is correct
5 Correct 182 ms 13688 KB Output is correct
6 Correct 173 ms 13432 KB Output is correct
7 Correct 178 ms 13304 KB Output is correct
8 Correct 179 ms 13688 KB Output is correct
9 Correct 177 ms 13480 KB Output is correct
10 Correct 176 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 11948 KB Output is correct
2 Correct 157 ms 12024 KB Output is correct
3 Correct 156 ms 11768 KB Output is correct
4 Correct 157 ms 11896 KB Output is correct
5 Correct 179 ms 13440 KB Output is correct
6 Correct 155 ms 11772 KB Output is correct
7 Correct 158 ms 12024 KB Output is correct
8 Correct 182 ms 13884 KB Output is correct
9 Correct 182 ms 13432 KB Output is correct
10 Correct 159 ms 12024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 13816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 174 ms 13560 KB Output is correct
2 Correct 178 ms 13560 KB Output is correct
3 Correct 182 ms 13944 KB Output is correct
4 Correct 181 ms 13688 KB Output is correct
5 Correct 182 ms 13688 KB Output is correct
6 Correct 173 ms 13432 KB Output is correct
7 Correct 178 ms 13304 KB Output is correct
8 Correct 179 ms 13688 KB Output is correct
9 Correct 177 ms 13480 KB Output is correct
10 Correct 176 ms 13560 KB Output is correct
11 Correct 152 ms 11948 KB Output is correct
12 Correct 157 ms 12024 KB Output is correct
13 Correct 156 ms 11768 KB Output is correct
14 Correct 157 ms 11896 KB Output is correct
15 Correct 179 ms 13440 KB Output is correct
16 Correct 155 ms 11772 KB Output is correct
17 Correct 158 ms 12024 KB Output is correct
18 Correct 182 ms 13884 KB Output is correct
19 Correct 182 ms 13432 KB Output is correct
20 Correct 159 ms 12024 KB Output is correct
21 Incorrect 190 ms 13816 KB Output isn't correct
22 Halted 0 ms 0 KB -