Submission #1258817

#TimeUsernameProblemLanguageResultExecution timeMemory
1258817phtungFeast (NOI19_feast)C++20
21 / 100
1096 ms327680 KiB
#include <bits/stdc++.h>

using namespace std;

#define name "IO"
#define int long long 

const int inf = 1e18 + 7; 
const int maxn = 3e5 + 5;
int n, k, a[maxn]; 

int Pow(int x, int y) 
{
    int ans = 1;
    while (y > 0) 
    {
        if (y & 1) ans = ans * x;
        y /= 2;
        x = x * x;
    }
    return ans;
}

void solve()
{
    cin >> n >> k;

    vector<int> pre(n + 1, 0); 

    for(int i = 1; i <= n; i++) 
    {
        cin >> a[i];
        pre[i] = pre[i - 1] + a[i];
    } 

    vector<vector<int>> dp(k + 1, vector<int>(n + 1, 0)); 

    for(int i = 1; i <= k; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            int mx = 0; 
            for(int l = 0; l < j; l++)
            {
                mx = max(mx, dp[i - 1][l] - pre[l]);
            }

            dp[i][j] = max(dp[i][j - 1], pre[j] + mx); 
        }
    }

    int res = 0;
    for(int i = 1; i <= n; i++) res = max(res, dp[k][i]);

    cout << res << "\n"; 
}


signed main()
{
    if (fopen (name".INP", "r"))
    {
        freopen (name".INP", "r", stdin);
        freopen (name".OUT", "w", stdout);
    }

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    clock_t start = clock(); 

    int t = 1;

    while(t--) solve(); 

    std::cerr << "Time: " << clock() - start << "ms\n";

    return 0; 

}

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:63:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen (name".INP", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:64:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen (name".OUT", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...