为何出错??
查看原帖
为何出错??
377768
Tooler_Yang楼主2022/7/20 09:28
#include<bits/stdc++.h>
using namespace std;
int a[500];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int maxx=0xc0c0c0c0;
    for(int l=1;l<=n;l++){
        for(int r=l;r<=n;r++){
            int t[500];
            for(int i=1;i<=n;i++) t[i]=a[i];
            for(int i=1;i<=k;i++){
                int in=0,out=0,sub=0xc0c0c0c0;
                for(int j=1;j<=r;j++){
                    for(int p=1;p<l;p++){
                        if(t[p]>t[j]&&t[p]-t[j]>sub&&t[p]-t[j]>0){
                            in=j,out=p,sub=a[p]-a[j];
                        }
                    }
                    for(int p=r+1;p<=n;p++){
                        if(t[p]>t[j]&&t[p]-t[j]>sub&&t[p]-t[j]>0){
                            in=j,out=p,sub=t[p]-t[j];
                        }
                    }
                }
                swap(t[in],t[out]);
//                cout<<in<<" "<<out<<"\n";
            }
//                for(int i=1;i<=n;i++){
//                    cout<<t[i]<<" ";
//                }
//                cout<<"\n";
//                cout<<l<<" "<<r<<"\n";
            int sum=0;
            for(int p=l;p<=r;p++){
                sum+=t[p];
            }
//            cout<<sum<<" "<<maxx<<"\n\n";
            maxx=max(maxx,sum);
        }
    }
    cout<<maxx;
    return 0;
}

在cf上评测wa在了第4个点

input:

29 6

-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7

Participant's output

6176

Jury's answer

6299

2022/7/20 09:28
加载中...