답안 #417611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417611 2021-06-04T03:43:45 Z Trickster Stove (JOI18_stove) C++14
100 / 100
24 ms 3408 KB
//Suleyman Atayew

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <map>
#include <set>
 
#define N 200010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) (int)(a.size())
ll bigmod(ll a, ll b) { if(b==0)return 1; ll ret = bigmod(a, b/2); return ret * ret % mod * (b%2 ? a : 1) % mod; }

using namespace std;

int n, k;
int v[N];
vector <pii> V;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);

    cin >> n >> k;

    for(int i = 1; i <= n; i++)
        cin >> v[i];

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int x = i;
        while(v[i] == v[i+1]-1) i++;

        V.pb({v[x], v[i]});
        ans += v[i]-v[x]+1;
    }

    vector <int> dis;
    for(int i = 1; i < sz(V); i++)
        dis.pb(V[i].ff-V[i-1].ss-1);
    
    sort(dis.begin(), dis.end());

    for(int i = 0; i < sz(V)-k; i++)
        ans += dis[i];

    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 23 ms 3372 KB Output is correct
17 Correct 23 ms 3292 KB Output is correct
18 Correct 23 ms 3388 KB Output is correct
19 Correct 23 ms 3264 KB Output is correct
20 Correct 23 ms 3328 KB Output is correct
21 Correct 23 ms 3332 KB Output is correct
22 Correct 24 ms 3408 KB Output is correct
23 Correct 23 ms 3260 KB Output is correct
24 Correct 23 ms 3248 KB Output is correct