Codeforces Round #243 (Div. 1) A题

时间:2023-03-09 16:27:30
Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接;

然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱!

直接暴力求出矩阵数值,然后枚举每一个【I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了

CODE:#include <cstdio>

#include <cstring>
#include <queue>
#include <vector>
#include<iostream>
#include<algorithm>
using namespace std;
int a[],b[];
int x[],y[];
int mp[][];
int n,m;
int cmp(int x,int y)
{
    return x>y;
}
int main()
{
    cin>>n>>m;
    int ma=-;
    for (int i=;i<=n;i++){
     cin>>a[i];
     ma=max(ma,a[i]);
    }
    if (ma<=) {cout<<ma<<endl;return ;}
     int o,p;
        for (int i=;i<=n;i++)
        for (int j=i;j<=n;j++)
        {
        for (int k=i;k<=j;k++)
         mp[i][j]+=a[k];
                o=p=;
                int t=mp[i][j];
                for (int k=;k<=n;k++){
                if (k>=i&&k<=j)
                    x[++o]=a[k];
                    else y[++p]=a[k];
                }
                sort(x+,x+o+);
                sort(y+,y+p+,cmp);
                o=min(o,p);
                o=min(o,m);
                for (int k=;k<=o;k++)
                    if (y[k]>x[k])
                t=t-x[k]+y[k];
                ma=max(ma,t);
        }
    cout<<ma<<endl;
return ;

}