結果

問題 No.1391 ±1 Abs Sum
ユーザー ocvret_ocvret_
提出日時 2021-02-12 23:26:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 818 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 166,084 KB
実行使用メモリ 4,624 KB
最終ジャッジ日時 2023-09-27 06:58:15
合計ジャッジ時間 4,691 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 76 ms
4,516 KB
testcase_12 AC 56 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 46 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 60 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 76 ms
4,376 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 78 ms
4,512 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 82 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  ll n,k;
  cin >> n >> k;
  k = n-k;
  ll r = n-k,x = k,l = 0;
  ll d = 0;
  ll res = 1ll << 60;
  vector<ll> a(n);
  rep(i,n)cin >> a[i],d += a[i]-a[0];
  for(ll i = r;i < n;i++)d -= (a[i]-a[0])*2;
  res = d;
  for(ll i = 1;i < n;i++){
    d += (i-2*(k-x))*(a[i]-a[i-1]);
    d -= (n-i-2*x)*(a[i]-a[i-1]);
    while(abs(a[i]-a[r]) < abs(a[i]-a[l])){
      d += 2*(abs(a[i]-a[l])-abs(a[i]-a[r]));
      l++;r++;
      l %= n;r %= n;
      x--;
    }
    res = min(res,d);
  }
  cout << res << "\n";
  

  return 0;
}
0