Submission #1188275

#TimeUsernameProblemLanguageResultExecution timeMemory
1188275sitingfakeFeast (NOI19_feast)C++20
100 / 100
97 ms12104 KiB
#include<bits/stdc++.h> using namespace std; // define #define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"; #define ll long long #define int long long #define ld long double #define ii pair<int,int> #define se second #define fi first #define iii pair<int,ii> #define all(v) v.begin(),v.end() #define bit(x,i) (((x)>>(i))&1LL) #define flip(x,i) ((x)^(1LL<<(i))) #define ms(d,x) memset(d,x,sizeof(d)) #define sitingfake 1 #define orz 1 template<typename T> bool maximize(T &a, const T &b) { if(a < b) {a = b; return 1;} return 0; } template<typename T> bool minimize(T &a, const T &b) { if(a > b) {a = b;return 1;} return 0; } //constant const ll mod = 1e9+7; const long long linf = 4557430888798830399; const int inf = 1061109567; const int maxarr = 1e6+5; const int dx[] = {0,1,-1,0}; const int dy[] = {1,0,0,-1}; //code const int maxn = 3e5 + 7; ii dp[maxn][2]; int n , k; ll a[maxn]; ii check(ll lamda) { dp[1][0] = ii(0,0); dp[1][1] = ii(a[1] - lamda,1); for(int i=2;i<=n;i++) { dp[i][0] = max(dp[i-1][0],dp[i-1][1]); dp[i][1] = max(ii(dp[i-1][0].fi + a[i] - lamda,dp[i-1][0].se + 1),ii(dp[i-1][1].fi + a[i],dp[i-1][1].se)); } return max(dp[n][0],dp[n][1]); } void solve(void) { cin >> n >> k; for(int i=1;i<=n;i++) { cin >> a[i]; } ll l = 0, r = 0, ans = 0; for(int i=1;i<=n;i++) { if(a[i] > 0) r += a[i]; } while(l <= r) { int mid = (r + l) >> 1; if(check(mid).se >= k) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << check(ans).fi + ans * 1ll *k; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int tc; tc = 1; while(tc--) solve(); //execute; } /** **/

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:103:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |        freopen(task".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
feast.cpp:104:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |        freopen(task".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...