Submission #238288

#TimeUsernameProblemLanguageResultExecution timeMemory
238288PbezzFeast (NOI19_feast)C++14
30 / 100
199 ms10492 KiB
#include <bits/stdc++.h> using namespace std; #define loop(i,n) for (ll i = 0; i < n; i++) #define ll long long #define INF 1e9+5 #define MAXN 200007 #define pb push_back #define mp make_pair typedef pair<ll,ll> pii; int main(){ ll n,i,k,ans,count=0,mini,x; cin>>n>>k; vector<ll>a(n+1); vector<ll>dp(n+1); for(i=1;i<=n;i++){ cin>>a[i]; if(a[i]<0){count++; mini=i;} dp[i]=dp[i-1]+a[i]; } if(count==0){ ans=dp[n]; }else if(count==1){ if(k>=2)ans=dp[n]-a[mini]; else{ x=dp[n]-dp[mini]; ans=max(dp[n], max(dp[mini-1], x)); } }else if(k==1){//clássico maximum sum subarray ans=0; vector<ll>bruh(n+1); for(i=1;i<=n;i++){ bruh[i]=max(bruh[i-1],(ll int)0)+a[i]; ans=max(ans,bruh[i]); } }else{ } printf("%lld\n",ans); return 0; }
#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...