Submission #833137

#TimeUsernameProblemLanguageResultExecution timeMemory
833137veehjFeast (NOI19_feast)C++17
4 / 100
1081 ms5044 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
int n, k; vector<ll> a={0};

void f(){
    vector<ll> p=a;
    for(int i=1; i<p.size(); i++) p[i]+=p[i-1];
    ll ans=0;
    for(int i=0; i<p.size(); i++){
        for(int j=0; j<i; j++){
            ans=max(ans, p[i]-p[j]);
        }
    }
    cout << ans << endl;
    return;
}

int main(){
    cin >> n >> k;
    for(int i=0; i<n; i++){
        ll x; cin >> x;
        a.pb(x);
    }
    if(k==1) f();
    else{
        ll cnt=0;
        for(auto& u : a) if(u>0) cnt+=u;
        cout << cnt << endl;
    }
}

Compilation message (stderr)

feast.cpp: In function 'void f()':
feast.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=1; i<p.size(); i++) p[i]+=p[i-1];
      |                  ~^~~~~~~~~
feast.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0; i<p.size(); i++){
      |                  ~^~~~~~~~~
#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...