Submission #791933

# Submission time Handle Problem Language Result Execution time Memory
791933 2023-07-24T12:40:26 Z vjudge1 Feast (NOI19_feast) C++17
12 / 100
76 ms 7984 KB
//i_love_aisukiuwu
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#include "/home/trucmai/.vim/tools.h"
	#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
	#else
	#define debug(x...)
#endif

void open(){
  if(fopen("i.inp","r")){
    freopen("i.inp","r",stdin);
    freopen("o.out","w",stdout);
  }
}

#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "

const int MN1 = 1e6 + 5,MN2 = 2e3 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,k,a[MN1],pf[MN1];

void solve(){
  cin>>n>>k;
  for(ll i = 1;i <= n;++i){
    cin>>a[i];
    pf[i] = pf[i-1] + a[i];
  } 
  ll l = 0,r = INF,res = 0;
  auto dp=[&](ll x)->pi{
    pi mx = {0,0},f = {0,0};
    for(ll i = 1;i <= n;++i){
      f = max(f,{mx.fi + pf[i] - x,mx.se - 1}); 
      mx = max(mx,{f.fi - pf[i],f.se});
    }
    f.se *= -1;
    return f;
  };
  while(l <= r){
    ll m = (r+l) >> 1; 
    auto [val,cnt] = dp(m);
    debug(l,r,cnt);
    if(cnt <= k){
      r = m - 1;
      res = val + k*m;
    }
    else l = m + 1;
  }
  cout<<res;
}

signed main(){
  cin.tie(0) -> sync_with_stdio(0);
  open();
  ll t = 1; //cin>>t;
  while(t--) solve(); 
  
  #ifdef LOCAL
    cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}

Compilation message

feast.cpp: In function 'void open()':
feast.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("i.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
feast.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("o.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7608 KB Output is correct
2 Correct 33 ms 7756 KB Output is correct
3 Correct 34 ms 7832 KB Output is correct
4 Correct 34 ms 7732 KB Output is correct
5 Correct 32 ms 7680 KB Output is correct
6 Correct 31 ms 7596 KB Output is correct
7 Correct 33 ms 7692 KB Output is correct
8 Correct 32 ms 7756 KB Output is correct
9 Correct 38 ms 7596 KB Output is correct
10 Correct 32 ms 7692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 5972 KB Output is correct
2 Correct 35 ms 6052 KB Output is correct
3 Correct 26 ms 5920 KB Output is correct
4 Correct 24 ms 6060 KB Output is correct
5 Correct 39 ms 7516 KB Output is correct
6 Correct 26 ms 5972 KB Output is correct
7 Correct 26 ms 6100 KB Output is correct
8 Correct 33 ms 7608 KB Output is correct
9 Correct 34 ms 7308 KB Output is correct
10 Correct 25 ms 6036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 7984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7608 KB Output is correct
2 Correct 33 ms 7756 KB Output is correct
3 Correct 34 ms 7832 KB Output is correct
4 Correct 34 ms 7732 KB Output is correct
5 Correct 32 ms 7680 KB Output is correct
6 Correct 31 ms 7596 KB Output is correct
7 Correct 33 ms 7692 KB Output is correct
8 Correct 32 ms 7756 KB Output is correct
9 Correct 38 ms 7596 KB Output is correct
10 Correct 32 ms 7692 KB Output is correct
11 Correct 29 ms 5972 KB Output is correct
12 Correct 35 ms 6052 KB Output is correct
13 Correct 26 ms 5920 KB Output is correct
14 Correct 24 ms 6060 KB Output is correct
15 Correct 39 ms 7516 KB Output is correct
16 Correct 26 ms 5972 KB Output is correct
17 Correct 26 ms 6100 KB Output is correct
18 Correct 33 ms 7608 KB Output is correct
19 Correct 34 ms 7308 KB Output is correct
20 Correct 25 ms 6036 KB Output is correct
21 Incorrect 76 ms 7984 KB Output isn't correct
22 Halted 0 ms 0 KB -