Submission #00007
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector< int >vint; typedef pair< int , int >pint; typedef vector<pint>vpint; template < typename A, typename B> inline void chmin(A &a,B b){ if (a>b)a=b;} template < typename A, typename B> inline void chmax(A &a,B b){ if (a<b)a=b;} int N,K; void solve(){ scanf ( "%lld%lld" ,&N,&K); chmin(K,N); vint x(N); rep(i,N) scanf ( "%lld" ,&x[i]); int ans=x[N-1]-x[0]; vint lis; rep(i,N-1)lis.pb(x[i+1]-x[i]); sort(all(lis)); reverse(all(lis)); rep(i,K-1)ans-=lis[i]; cout<<ans<<endl; } signed main(){ int T; scanf ( "%lld" ,&T); while (T--)solve(); return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0011 - カントリーロード |
ユーザー名 | latte0119 |
投稿日時 | 2017-03-30 20:02:59 |
言語 | C++11 |
状態 | Accepted |
得点 | 25 |
ソースコード長 | 838 Byte |
最大実行時間 | 57 ms |
最大メモリ使用量 | 3084 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 25 / 25 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
road.in | AC | 57 ms | 3084 KB |
1
|