Submission #792033

# Submission time Handle Problem Language Result Execution time Memory
792033 2023-07-24T14:06:06 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
107 ms 6460 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];

pi get(const pi &a,const pi &b){
  if(a.fi != b.fi) return (a.fi > b.fi ? a : b); 
  else return (a.se < b.se ? a : b);
}

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 = 3e14,res = 0;
  auto dp=[&](ll x)->pi{
    pi mx = {0,0},f = {0,0};
    for(ll i = 1;i <= n;++i){
      f = get(f,{mx.fi + pf[i] - x,mx.se + 1}); 
      mx = get(mx,{f.fi - pf[i],f.se});
    }
    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 39 ms 5960 KB Output is correct
2 Correct 40 ms 6088 KB Output is correct
3 Correct 42 ms 6084 KB Output is correct
4 Correct 42 ms 6084 KB Output is correct
5 Correct 39 ms 6024 KB Output is correct
6 Correct 38 ms 5920 KB Output is correct
7 Correct 38 ms 6028 KB Output is correct
8 Correct 40 ms 6060 KB Output is correct
9 Correct 40 ms 6036 KB Output is correct
10 Correct 43 ms 6080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 5928 KB Output is correct
2 Correct 42 ms 6148 KB Output is correct
3 Correct 37 ms 5964 KB Output is correct
4 Correct 34 ms 5996 KB Output is correct
5 Correct 39 ms 6192 KB Output is correct
6 Correct 38 ms 5964 KB Output is correct
7 Correct 34 ms 6136 KB Output is correct
8 Correct 43 ms 6460 KB Output is correct
9 Correct 47 ms 6188 KB Output is correct
10 Correct 34 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 6112 KB Output is correct
2 Correct 66 ms 5984 KB Output is correct
3 Correct 66 ms 6144 KB Output is correct
4 Correct 65 ms 5984 KB Output is correct
5 Correct 64 ms 6092 KB Output is correct
6 Correct 65 ms 6120 KB Output is correct
7 Correct 67 ms 6144 KB Output is correct
8 Correct 80 ms 6076 KB Output is correct
9 Correct 67 ms 6040 KB Output is correct
10 Correct 66 ms 6072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 392 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 5960 KB Output is correct
2 Correct 40 ms 6088 KB Output is correct
3 Correct 42 ms 6084 KB Output is correct
4 Correct 42 ms 6084 KB Output is correct
5 Correct 39 ms 6024 KB Output is correct
6 Correct 38 ms 5920 KB Output is correct
7 Correct 38 ms 6028 KB Output is correct
8 Correct 40 ms 6060 KB Output is correct
9 Correct 40 ms 6036 KB Output is correct
10 Correct 43 ms 6080 KB Output is correct
11 Correct 38 ms 5928 KB Output is correct
12 Correct 42 ms 6148 KB Output is correct
13 Correct 37 ms 5964 KB Output is correct
14 Correct 34 ms 5996 KB Output is correct
15 Correct 39 ms 6192 KB Output is correct
16 Correct 38 ms 5964 KB Output is correct
17 Correct 34 ms 6136 KB Output is correct
18 Correct 43 ms 6460 KB Output is correct
19 Correct 47 ms 6188 KB Output is correct
20 Correct 34 ms 6100 KB Output is correct
21 Correct 64 ms 6112 KB Output is correct
22 Correct 66 ms 5984 KB Output is correct
23 Correct 66 ms 6144 KB Output is correct
24 Correct 65 ms 5984 KB Output is correct
25 Correct 64 ms 6092 KB Output is correct
26 Correct 65 ms 6120 KB Output is correct
27 Correct 67 ms 6144 KB Output is correct
28 Correct 80 ms 6076 KB Output is correct
29 Correct 67 ms 6040 KB Output is correct
30 Correct 66 ms 6072 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 324 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 392 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 93 ms 6196 KB Output is correct
62 Correct 93 ms 6396 KB Output is correct
63 Correct 77 ms 6192 KB Output is correct
64 Correct 95 ms 6360 KB Output is correct
65 Correct 98 ms 6368 KB Output is correct
66 Correct 96 ms 6360 KB Output is correct
67 Correct 107 ms 6272 KB Output is correct
68 Correct 69 ms 6288 KB Output is correct
69 Correct 64 ms 6288 KB Output is correct
70 Correct 64 ms 6232 KB Output is correct