codeforces 1175 D. Array Splitting

Posted gaudar

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 1175 D. Array Splitting相关的知识,希望对你有一定的参考价值。

题意:n长序列分成m段非空串。使得式子和最大。

求后缀和,题目中的式子相当于,选m个后缀和相加。其中sum[1]为必选。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
#define err cout<<"err"<<endl
using namespace std;
const double EPS=1e-8;
typedef long long lon;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const lon SZ=300010,SSZ=SZ*SZ,APB=4,one=1;
const lon INF=0x3f3f3f3f,mod=1000000007;
lon n,m,arr[SZ],sum[SZ];

void init()

    cin>>n>>m;
    for(int i=1;i<=n;++i)cin>>arr[i];
    for(int i=n;i>=1;--i)
    
        sum[i]=sum[i+1]+arr[i];
    
    lon res=sum[1];
    sort(sum+2,sum+1+n);
    for(int i=n;(n-i+1)<=m-1;--i)
    
        res+=sum[i];
    
    cout<<res<<endl;


void work()

    


void release()

    


int main()

    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //cout<<casenum<<endl;
    //for(lon tim=1;tim<=casenum;++tim)
    //for(lon tim=1;cin>>n;++tim)
    
        //cout<<"Case #"<<tim<<": ";
        init();
        work();
        release();
    
    return 0;

 

以上是关于codeforces 1175 D. Array Splitting的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 63 D. Beautiful Array

Codeforces Round #643 (Div. 2) D. Game With Array(构造)

Codeforces Round #643 (Div. 2) D. Game With Array(构造)

Codeforces Round #504 D. Array Restoration

Codeforces Round #653 (Div. 3)D. Zero Remainder Array

Codeforces Round #775 (Div. 2,based on Moscow Open Olympiad in Informatics) - D. Integral Array - 题解