Submission #1177672

#TimeUsernameProblemLanguageResultExecution timeMemory
1177672tamzidFeast (NOI19_feast)C++20
4 / 100
20 ms400 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using ll = long long;
#define pb push_back
#define F first
#define S second
#define vii vector<int>
#define vl vector<long long>
#define cinv(v)  for (auto &it : v) cin >> it;
#define coutv(v) for (auto &it : v) cout << it << " "; cout << endl;
using namespace std;
//using namespace __gnu_pbds;
//template<class T> using ordset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    int n,k;
    cin>>n>>k;
    ll ans = 0;
    ll temp = INT_MIN;
    for(int i=0;i<n;++i)
    {
        ll x;
        cin>>x;
        if(x>=0)
        {
            ans+=x;
        }
        else
        {
            if(k==1)
            {
                ll temp = ans;
                ans = 0;
            }
        }
    }
    cout<<max(ans,temp);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //int t;cin>>t;while(t--)
        solve();

    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...