結果

問題 No.1391 ±1 Abs Sum
ユーザー eSeFeSeF
提出日時 2020-11-08 13:59:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 924 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 204,112 KB
実行使用メモリ 6,972 KB
最終ジャッジ日時 2023-09-29 21:11:54
合計ジャッジ時間 30,668 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 768 ms
5,084 KB
testcase_15 AC 813 ms
4,996 KB
testcase_16 AC 1,039 ms
6,284 KB
testcase_17 AC 908 ms
6,088 KB
testcase_18 AC 1,258 ms
6,516 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1,415 ms
6,812 KB
testcase_32 AC 693 ms
4,940 KB
testcase_33 AC 800 ms
4,928 KB
testcase_34 AC 1,336 ms
6,672 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 829 ms
6,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const ll inf = 4611686018427387903LL;
const int MOD=998244353;
int main()
{
  int N,K;
  cin >> N >> K;
  vector<ll>a(N);rep(i,N)cin >> a[i];
  ll ans=inf;
  int w=25;
  priority_queue<ll>q;
  for(int i=0;i<min(N,w);i++){
    rep(j,N)q.push(abs(a[i]-a[j]));
    ll s=0;
    rep(j,N){
      if(j<N-K)s-=q.top();
      else s+=q.top();
      q.pop();
    }
    ans=min(ans,s);
  }
  for(int i=N-1;i>=max(0,N-1-w);i--){
    rep(j,N)q.push(abs(a[i]-a[j]));
    ll s=0;
    rep(j,N){
      if(j<N-K)s-=q.top();
      else s+=q.top();
      q.pop();
    }
    ans=min(ans,s);
  }
  for(int i=max(0,N/2-w/2);i<min(N,N/2+w/2);i++){
    rep(j,N)q.push(abs(a[i]-a[j]));
    ll s=0;
    rep(j,N){
      if(j<N-K)s-=q.top();
      else s+=q.top();
      q.pop();
    }
    ans=min(ans,s);
  }
  cout << ans << endl;
  return 0;
}
0