답안 #145592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145592 2019-08-20T13:14:47 Z mat_v Stove (JOI18_stove) C++14
100 / 100
29 ms 3316 KB
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define mid(l, r) ((l)+(r))/2
#define len(a) (a).length()
#define sz(a) (a).size()
#define xx first
#define yy second
#define inf int(2e9)
#define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int n,k;
ll niz[300005];
vector<ll>val;
ll res;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    ff(i,0,n - 1){
        cin >> niz[i];
    }
    sort(niz, niz + n);
    ff(i,0,n-2){
        val.pb(niz[i] - niz[i + 1]);
        //cout << niz[i] - niz[i+1] << endl;
    }
    int tmpk = k;
    sort(val.begin(), val.end());
    for(auto c:val){
        if(k==1)break;
        res += c;
        k--;
        if(k == 1)break;
    }
    res += niz[n-1];
    res -= niz[0];
    cout << res + tmpk;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 388 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 388 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 28 ms 3288 KB Output is correct
17 Correct 28 ms 3188 KB Output is correct
18 Correct 28 ms 3188 KB Output is correct
19 Correct 28 ms 3192 KB Output is correct
20 Correct 28 ms 3316 KB Output is correct
21 Correct 28 ms 3316 KB Output is correct
22 Correct 29 ms 3316 KB Output is correct
23 Correct 28 ms 3316 KB Output is correct
24 Correct 28 ms 3184 KB Output is correct