답안 #791935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791935 2023-07-24T12:41:00 Z trucmai Feast (NOI19_feast) C++17
12 / 100
72 ms 5000 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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4820 KB Output is correct
2 Correct 31 ms 4956 KB Output is correct
3 Correct 31 ms 4968 KB Output is correct
4 Correct 37 ms 4864 KB Output is correct
5 Correct 31 ms 4976 KB Output is correct
6 Correct 30 ms 4820 KB Output is correct
7 Correct 30 ms 4832 KB Output is correct
8 Correct 31 ms 4912 KB Output is correct
9 Correct 35 ms 4788 KB Output is correct
10 Correct 35 ms 4864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 4904 KB Output is correct
2 Correct 27 ms 5000 KB Output is correct
3 Correct 27 ms 4828 KB Output is correct
4 Correct 32 ms 4932 KB Output is correct
5 Correct 31 ms 4872 KB Output is correct
6 Correct 25 ms 4908 KB Output is correct
7 Correct 24 ms 4996 KB Output is correct
8 Correct 31 ms 4960 KB Output is correct
9 Correct 30 ms 4824 KB Output is correct
10 Correct 24 ms 5000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 4960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4820 KB Output is correct
2 Correct 31 ms 4956 KB Output is correct
3 Correct 31 ms 4968 KB Output is correct
4 Correct 37 ms 4864 KB Output is correct
5 Correct 31 ms 4976 KB Output is correct
6 Correct 30 ms 4820 KB Output is correct
7 Correct 30 ms 4832 KB Output is correct
8 Correct 31 ms 4912 KB Output is correct
9 Correct 35 ms 4788 KB Output is correct
10 Correct 35 ms 4864 KB Output is correct
11 Correct 29 ms 4904 KB Output is correct
12 Correct 27 ms 5000 KB Output is correct
13 Correct 27 ms 4828 KB Output is correct
14 Correct 32 ms 4932 KB Output is correct
15 Correct 31 ms 4872 KB Output is correct
16 Correct 25 ms 4908 KB Output is correct
17 Correct 24 ms 4996 KB Output is correct
18 Correct 31 ms 4960 KB Output is correct
19 Correct 30 ms 4824 KB Output is correct
20 Correct 24 ms 5000 KB Output is correct
21 Incorrect 72 ms 4960 KB Output isn't correct
22 Halted 0 ms 0 KB -