Submission #971442

#TimeUsernameProblemLanguageResultExecution timeMemory
971442mychecksedadFeast (NOI19_feast)C++17
100 / 100
135 ms18036 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30; const double eps = 0.00001; int n, k; ll a[N]; pair<ll, int> dp[N][2]; pair<ll, int> f(ll lambda){ dp[1][0] = {0, 0}; dp[1][1] = {a[1] - lambda, 1}; for(int i = 2; i <= n; ++i){ dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max(pair<ll,int>{dp[i - 1][0].first + a[i] - lambda, dp[i - 1][0].second + 1}, pair<ll,int>{dp[i - 1][1].first + a[i], dp[i - 1][1].second}); } // cout << dp[1][1].first << ' '; return max(dp[n][0], dp[n][1]); } void solve(){ cin >> n >> k; for(int i = 1; i <= n; ++i) cin >> a[i]; ll l = 0, r = 1e18, lambda = 0; while(l <= r){ ll m = (l+r)/2; if(f(m).second <= k){ lambda = m; r = m - 1; }else{ l = m + 1; } } // cout << f(lambda).second << ' '; cout << (ll)(f(lambda).first + lambda * k); } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); en; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:48:15: warning: unused variable 'aa' [-Wunused-variable]
   48 |   int tt = 1, aa;
      |               ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...