[悬关] 简单题求思路
  • 板块学术版
  • 楼主Lovely_Elaina
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/4/1 18:59
  • 上次更新2023/10/23 19:45:03
查看原帖
[悬关] 简单题求思路
781159
Lovely_Elaina楼主2023/4/1 18:59

#include <bits/stdc++.h>
// #include <iostream>
#define int long long
#define max(a,b) (a>b?a:b)
// #define min(a,b) (a<b?a:b)
using namespace std;
const int N = 100005;

int n,c,x,y;
int p,t,mi;
int a[N],s;
int b[N];

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    
    cin >> n >> c >> x;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    
    sort(a+1,a+1+n);
    
    int ma = 0;
    for(int i = 1; i <= n; i++){
        p = a[i];
        s++,t++;
        
        if(t == 1) mi = i;
        if(t == x || i == n){
            b[i] = mi;
            ma = max(p-a[mi],ma);
            // cout << t << " " << p << " " << mi << endl;
            t = 0,y++;
        }
    }
    
    if(n % x){
        if(1){}
    }
    
    while(1){break;} //
    
    
    cout << ma << endl;
    return 0;
}

想到大概这样解,但是总感觉有更优解()

2023/4/1 18:59
加载中...