Submission #1103138

# Submission time Handle Problem Language Result Execution time Memory
1103138 2024-10-20T09:09:40 Z joyboy23ti Feast (NOI19_feast) C++14
71 / 100
214 ms 221344 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i,l,r) for (int i = l; i <= r; i++)
#define FORD(i,l,r) for (int i = l; i >= r; i--)
#define el cout <<"\n"
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&(1LL))
#define Debug(a,n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> vii;
typedef unsigned long long ull;
typedef vector<vector<int>> vvi;
int fastMax(int x, int y)
{
    return (((y-x)>>(32-1))&(x^y))^y;
}

const int N=1e6+5;
const int base=311;
const int mod=1e9+7;
const long long INF=1e18+7;
const int d4x[4] = {-1, 0, 1, 0}, d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};
template<class X, class Y> bool maximize(X &x, Y y)
{
    if (x < y)
    {
        x = y;
        return true;
    }
    return false;
};
template<class X, class Y> bool minimize(X &x, Y y)
{
    if (x > y)
    {
        x = y;
        return true;
    }
    return false;
};
void add(int &x, int y)
{
    x += y;
    if (x>=mod) x-=mod;
}
void sub(int &x, int y)
{
    x -= y;
    if (x<0) x+=mod;
}
int mul(int x, int y)
{
    return 1LL * x * y % mod;
}
int calPw(int x, int y)
{
    int ans = 1;
    while(y)
    {
        if (y&1) ans = 1LL * ans * x % mod;
        x = 1LL * x * x % mod;
        y >>= 1;
    }
    return ans;
}
///KhengmepfromLTVHSFTG
int n,a[N],k;
ll pre[N],dp[5005][5005];
ll dp2[N][3];
bool check=true,check2=true;
void khengmep()
{
    if(check==true)
    {
        ll sum=0;
        for(int i=1; i<=n; i++)
        {
            sum+=a[i];
        }
        cout<<sum;
        return;
    }
    if(check2==true&&k!=1)
    {
        for(int i=1; i<=n; i++)
        {
            if(a[i]<0)
            {
                cout<<pre[n]-a[i];
                return;
            }
        }
    }
    if(k==1)
    {
        for(int i=1; i<=k; i++)
        {
            ll maxx=-INF;
            for(int j=1; j<=n; j++)
            {
                maxx=max(maxx,dp2[j-1][i-1]-pre[j-1]);
                dp2[j][i]=max(maxx+pre[j],dp2[j-1][i]);
            }
        }
        cout<<dp2[n][k];
        return;
    }
    for(int i=1; i<=k; i++)
    {
        ll maxx=-INF;
        for(int j=1; j<=n; j++)
        {
            maxx=max(maxx,dp[j-1][i-1]-pre[j-1]);
            dp[j][i]=max(maxx+pre[j],dp[j-1][i]);
        }
    }
    cout<<dp[n][k];
}
void ip()
{
    cin>>n>>k;
    pre[0]=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(check==false&&a[i]<0) check2=false;
        if(a[i]<0) check=false;
        pre[i]=pre[i-1]+a[i];
    }
}
int main()
{
//    freopen("BANQUET.inp","r",stdin);
//    freopen("BANQUET.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        ip();
        khengmep();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 10568 KB Output is correct
2 Correct 21 ms 10576 KB Output is correct
3 Correct 28 ms 10576 KB Output is correct
4 Correct 21 ms 10576 KB Output is correct
5 Correct 22 ms 10456 KB Output is correct
6 Correct 22 ms 10576 KB Output is correct
7 Correct 22 ms 10720 KB Output is correct
8 Correct 20 ms 10576 KB Output is correct
9 Correct 22 ms 10576 KB Output is correct
10 Correct 22 ms 10580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19024 KB Output is correct
2 Correct 22 ms 18908 KB Output is correct
3 Correct 16 ms 19024 KB Output is correct
4 Correct 14 ms 10576 KB Output is correct
5 Correct 22 ms 19024 KB Output is correct
6 Correct 15 ms 19024 KB Output is correct
7 Correct 14 ms 10576 KB Output is correct
8 Correct 30 ms 19016 KB Output is correct
9 Correct 24 ms 19016 KB Output is correct
10 Correct 15 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 19024 KB Output is correct
2 Correct 26 ms 18920 KB Output is correct
3 Correct 24 ms 18912 KB Output is correct
4 Correct 25 ms 18900 KB Output is correct
5 Correct 25 ms 19016 KB Output is correct
6 Correct 26 ms 19024 KB Output is correct
7 Correct 34 ms 19016 KB Output is correct
8 Correct 25 ms 19024 KB Output is correct
9 Correct 27 ms 19016 KB Output is correct
10 Correct 25 ms 19032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4604 KB Output is correct
2 Correct 1 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 1 ms 6736 KB Output is correct
5 Correct 2 ms 6904 KB Output is correct
6 Correct 2 ms 6608 KB Output is correct
7 Correct 1 ms 6736 KB Output is correct
8 Correct 1 ms 6616 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4604 KB Output is correct
2 Correct 1 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 1 ms 6736 KB Output is correct
5 Correct 2 ms 6904 KB Output is correct
6 Correct 2 ms 6608 KB Output is correct
7 Correct 1 ms 6736 KB Output is correct
8 Correct 1 ms 6616 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
11 Correct 3 ms 14928 KB Output is correct
12 Correct 2 ms 14928 KB Output is correct
13 Correct 2 ms 15092 KB Output is correct
14 Correct 3 ms 14928 KB Output is correct
15 Correct 2 ms 14928 KB Output is correct
16 Correct 3 ms 14928 KB Output is correct
17 Correct 3 ms 14928 KB Output is correct
18 Correct 3 ms 14928 KB Output is correct
19 Correct 2 ms 14928 KB Output is correct
20 Correct 3 ms 14928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4604 KB Output is correct
2 Correct 1 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 1 ms 6736 KB Output is correct
5 Correct 2 ms 6904 KB Output is correct
6 Correct 2 ms 6608 KB Output is correct
7 Correct 1 ms 6736 KB Output is correct
8 Correct 1 ms 6616 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
11 Correct 3 ms 14928 KB Output is correct
12 Correct 2 ms 14928 KB Output is correct
13 Correct 2 ms 15092 KB Output is correct
14 Correct 3 ms 14928 KB Output is correct
15 Correct 2 ms 14928 KB Output is correct
16 Correct 3 ms 14928 KB Output is correct
17 Correct 3 ms 14928 KB Output is correct
18 Correct 3 ms 14928 KB Output is correct
19 Correct 2 ms 14928 KB Output is correct
20 Correct 3 ms 14928 KB Output is correct
21 Correct 10 ms 80464 KB Output is correct
22 Correct 26 ms 80976 KB Output is correct
23 Correct 12 ms 80720 KB Output is correct
24 Correct 10 ms 80464 KB Output is correct
25 Correct 11 ms 82512 KB Output is correct
26 Correct 10 ms 82512 KB Output is correct
27 Correct 11 ms 82512 KB Output is correct
28 Correct 9 ms 82512 KB Output is correct
29 Correct 9 ms 80464 KB Output is correct
30 Correct 9 ms 80464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 10568 KB Output is correct
2 Correct 21 ms 10576 KB Output is correct
3 Correct 28 ms 10576 KB Output is correct
4 Correct 21 ms 10576 KB Output is correct
5 Correct 22 ms 10456 KB Output is correct
6 Correct 22 ms 10576 KB Output is correct
7 Correct 22 ms 10720 KB Output is correct
8 Correct 20 ms 10576 KB Output is correct
9 Correct 22 ms 10576 KB Output is correct
10 Correct 22 ms 10580 KB Output is correct
11 Correct 16 ms 19024 KB Output is correct
12 Correct 22 ms 18908 KB Output is correct
13 Correct 16 ms 19024 KB Output is correct
14 Correct 14 ms 10576 KB Output is correct
15 Correct 22 ms 19024 KB Output is correct
16 Correct 15 ms 19024 KB Output is correct
17 Correct 14 ms 10576 KB Output is correct
18 Correct 30 ms 19016 KB Output is correct
19 Correct 24 ms 19016 KB Output is correct
20 Correct 15 ms 10576 KB Output is correct
21 Correct 26 ms 19024 KB Output is correct
22 Correct 26 ms 18920 KB Output is correct
23 Correct 24 ms 18912 KB Output is correct
24 Correct 25 ms 18900 KB Output is correct
25 Correct 25 ms 19016 KB Output is correct
26 Correct 26 ms 19024 KB Output is correct
27 Correct 34 ms 19016 KB Output is correct
28 Correct 25 ms 19024 KB Output is correct
29 Correct 27 ms 19016 KB Output is correct
30 Correct 25 ms 19032 KB Output is correct
31 Correct 1 ms 4604 KB Output is correct
32 Correct 1 ms 6736 KB Output is correct
33 Correct 2 ms 6736 KB Output is correct
34 Correct 1 ms 6736 KB Output is correct
35 Correct 2 ms 6904 KB Output is correct
36 Correct 2 ms 6608 KB Output is correct
37 Correct 1 ms 6736 KB Output is correct
38 Correct 1 ms 6616 KB Output is correct
39 Correct 1 ms 4432 KB Output is correct
40 Correct 1 ms 6736 KB Output is correct
41 Correct 3 ms 14928 KB Output is correct
42 Correct 2 ms 14928 KB Output is correct
43 Correct 2 ms 15092 KB Output is correct
44 Correct 3 ms 14928 KB Output is correct
45 Correct 2 ms 14928 KB Output is correct
46 Correct 3 ms 14928 KB Output is correct
47 Correct 3 ms 14928 KB Output is correct
48 Correct 3 ms 14928 KB Output is correct
49 Correct 2 ms 14928 KB Output is correct
50 Correct 3 ms 14928 KB Output is correct
51 Correct 10 ms 80464 KB Output is correct
52 Correct 26 ms 80976 KB Output is correct
53 Correct 12 ms 80720 KB Output is correct
54 Correct 10 ms 80464 KB Output is correct
55 Correct 11 ms 82512 KB Output is correct
56 Correct 10 ms 82512 KB Output is correct
57 Correct 11 ms 82512 KB Output is correct
58 Correct 9 ms 82512 KB Output is correct
59 Correct 9 ms 80464 KB Output is correct
60 Correct 9 ms 80464 KB Output is correct
61 Runtime error 214 ms 221344 KB Execution killed with signal 11
62 Halted 0 ms 0 KB -