提出 #4163666


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  ll N, M;
  cin >> N >> M;
  ll x[M], sa[M], res = 0;
  rep(i, M) {
    cin >> x[i];
  }
  if (N >= M) {
    cout << res << endl;
    exit(0);
  }
  sort(x, x+M);
  rep(i, M-1) {
    sa[i] = x[i+1] - x[i];
  }
  sort(sa, sa+M-1);
  rep(i, M-N){
    res += sa[i];
  }
  cout << res << endl;
}

提出情報

提出日時
問題 C - Streamline
ユーザ KeitaKishida0811
言語 C++14 (GCC 5.4.1)
得点 300
コード長 537 Byte
結果 AC
実行時間 39 ms
メモリ 1792 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 300 / 300 0 / 0
結果
AC × 23
AC × 3
セット名 テストケース
All 0_normal_1, 0_normal_2, 0_normal_3, 0_normal_4, 1_max_1, 1_max_2, 1_max_3, 1_max_4, 2_nsmall_1, 2_nsmall_2, 2_nsmall_3, 2_nsmall_4, 3_msmall_1, 3_msmall_2, 3_msmall_3, 3_msmall_4, 4_corner_1, 4_corner_2, 4_corner_3, 4_corner_4, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
ケース名 結果 実行時間 メモリ
0_normal_1 AC 1 ms 256 KiB
0_normal_2 AC 1 ms 256 KiB
0_normal_3 AC 16 ms 640 KiB
0_normal_4 AC 34 ms 1536 KiB
1_max_1 AC 17 ms 640 KiB
1_max_2 AC 15 ms 640 KiB
1_max_3 AC 31 ms 1024 KiB
1_max_4 AC 39 ms 1792 KiB
2_nsmall_1 AC 36 ms 1664 KiB
2_nsmall_2 AC 5 ms 384 KiB
2_nsmall_3 AC 31 ms 1408 KiB
2_nsmall_4 AC 10 ms 640 KiB
3_msmall_1 AC 1 ms 256 KiB
3_msmall_2 AC 1 ms 256 KiB
3_msmall_3 AC 1 ms 256 KiB
3_msmall_4 AC 1 ms 256 KiB
4_corner_1 AC 5 ms 384 KiB
4_corner_2 AC 28 ms 1408 KiB
4_corner_3 AC 1 ms 256 KiB
4_corner_4 AC 1 ms 256 KiB
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 1 ms 256 KiB