Submission #1097128

# Submission time Handle Problem Language Result Execution time Memory
1097128 2024-10-06T07:42:48 Z vjudge1 Feast (NOI19_feast) C++17
22 / 100
33 ms 7488 KB
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define int long long
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
vector<int> ans;
void maxsum(vector<int> &v){
    int n = v.size();
    int mx = INT_MIN, mx_ending = 0;
    for (int i = 0; i < n;i++){
        mx_ending = mx_ending + v[i];
        if(mx<mx_ending){
            mx = mx_ending;
        }
        if(mx_ending<0){
            if(mx>0)ans.push_back(mx);
            mx_ending = 0;
        }
    }
    if (mx_ending >0)
    {
        ans.push_back(mx);
    }
}
void solve(int tt)
{
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n;i++){
        int x;
        cin >> x;
        v.push_back(x);

    }
    maxsum(v);
    int ase = ans.size();
    int dorkar = min(ase, k);
    sort(ans.rbegin(), ans.rend());
    int sum = 0;
    for (int i = 0; i <dorkar;i++){
        //cout << ans[i] << " ";
        sum += ans[i];
    }
    cout << sum << endl;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    int tt = 1;
    while (t--)
    {
        solve(tt++);
    }
}

# Verdict Execution time Memory Grader output
1 Correct 24 ms 7368 KB Output is correct
2 Correct 22 ms 7372 KB Output is correct
3 Correct 22 ms 7380 KB Output is correct
4 Correct 22 ms 7324 KB Output is correct
5 Correct 23 ms 7272 KB Output is correct
6 Correct 23 ms 7128 KB Output is correct
7 Correct 22 ms 7376 KB Output is correct
8 Correct 23 ms 7172 KB Output is correct
9 Correct 23 ms 7348 KB Output is correct
10 Correct 25 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 5588 KB Output is correct
2 Correct 16 ms 5644 KB Output is correct
3 Correct 15 ms 5588 KB Output is correct
4 Incorrect 16 ms 5844 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 7488 KB Output is correct
2 Correct 25 ms 7380 KB Output is correct
3 Correct 28 ms 7456 KB Output is correct
4 Correct 27 ms 7372 KB Output is correct
5 Correct 33 ms 7444 KB Output is correct
6 Correct 31 ms 7312 KB Output is correct
7 Correct 26 ms 7380 KB Output is correct
8 Correct 26 ms 7424 KB Output is correct
9 Correct 27 ms 7392 KB Output is correct
10 Correct 27 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7368 KB Output is correct
2 Correct 22 ms 7372 KB Output is correct
3 Correct 22 ms 7380 KB Output is correct
4 Correct 22 ms 7324 KB Output is correct
5 Correct 23 ms 7272 KB Output is correct
6 Correct 23 ms 7128 KB Output is correct
7 Correct 22 ms 7376 KB Output is correct
8 Correct 23 ms 7172 KB Output is correct
9 Correct 23 ms 7348 KB Output is correct
10 Correct 25 ms 7380 KB Output is correct
11 Correct 18 ms 5588 KB Output is correct
12 Correct 16 ms 5644 KB Output is correct
13 Correct 15 ms 5588 KB Output is correct
14 Incorrect 16 ms 5844 KB Output isn't correct
15 Halted 0 ms 0 KB -