답안 #1017374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017374 2024-07-09T07:38:56 Z concac Feast (NOI19_feast) C++17
18 / 100
98 ms 12124 KB
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define pll2 pair<pll,ll>
#define bit(i,k) ((k>>i)&1)
#define pii pair<int,int>
#define mp make_pair

using namespace std;
const long long mod = 1e9+7;
const ll inf = 1e18;
const ll maxN = 3e5+5;
ll n,k;
ll a[maxN];
pll go(ll lambda){
  pll dp[n+5][2]={};//lay i hoac deo

  dp[0][1].ff=-inf;
  for(int i=1;i<=n;i++){
    dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
    pll p1={dp[i-1][0].ff+a[i]-lambda,dp[i-1][0].ss+1};
    pll p2={dp[i-1][1].ff+a[i],dp[i-1][1].ss};
    dp[i][1]=max(p1,p2);
  }

  return max(dp[n][1],dp[n][0]);
}
void solve() {
  cin>>n>>k;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  ll l=0,r=inf;
  ll lmd;
  ll ans=-inf;
  while(l<=r){
    ll md=(l+r)/2;
    pll p=go(md);
  
    if(p.ss>=k){ans=p.ff;lmd=md;l=md+1;}
    else{r=md-1;}
  }
  cout<<max(0ll,ans+k*lmd)<<'\n';


}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //  freopen("rao.inp", "r", stdin);
    // freopen("rao.out", "w", stdout);
    ll nhim = 1;
    // cin >> nhim;
    // cout<<nhim<<'\n';
    while (nhim--) {
        solve();
    }
}

Compilation message

feast.cpp: In function 'void solve()':
feast.cpp:51:22: warning: 'lmd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |   cout<<max(0ll,ans+k*lmd)<<'\n';
      |                     ~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 11604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 11868 KB Output is correct
2 Correct 60 ms 12124 KB Output is correct
3 Correct 62 ms 11868 KB Output is correct
4 Incorrect 59 ms 11912 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 11864 KB Output is correct
2 Correct 93 ms 11856 KB Output is correct
3 Correct 98 ms 11864 KB Output is correct
4 Correct 92 ms 11868 KB Output is correct
5 Correct 92 ms 11804 KB Output is correct
6 Correct 94 ms 11860 KB Output is correct
7 Correct 95 ms 12116 KB Output is correct
8 Correct 91 ms 11868 KB Output is correct
9 Correct 91 ms 12120 KB Output is correct
10 Correct 94 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 11604 KB Output isn't correct
2 Halted 0 ms 0 KB -