답안 #569577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569577 2022-05-27T14:18:08 Z Huy Stove (JOI18_stove) C++17
100 / 100
23 ms 3008 KB
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second

using namespace std;
using ll = long long;
using ldb = long double;
const int N = (int)1e8;
const int maxN = (int)1e6 + 1;
const int mod = 1e9 + 7;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n,k;
int T[maxN];
vector<int> su;
int res = 0;

void Read()
{
    cin >> n >> k;
    for(int i = 1;i <= n;i++)
    {
        cin >> T[i];
        if(i > 1)
        {
            res += T[i] - T[i-1];
            su.push_back(T[i] - T[i-1]);
        }
    }
    if(n == 1) {cout << 1;return;}
    sort(su.begin(),su.end(),greater<int>());
    for(int i = 0;i < k - 1;i++)
    {
        res -= su[i];
    }
    res += k;
    cout << res;
}

void Solve()
{

}

void Debug()
{
    //Main_sub();
    //Naive();
}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
    //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}



# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 23 ms 2968 KB Output is correct
17 Correct 19 ms 2896 KB Output is correct
18 Correct 23 ms 2920 KB Output is correct
19 Correct 20 ms 2900 KB Output is correct
20 Correct 20 ms 2976 KB Output is correct
21 Correct 18 ms 2872 KB Output is correct
22 Correct 19 ms 2880 KB Output is correct
23 Correct 20 ms 2896 KB Output is correct
24 Correct 20 ms 3008 KB Output is correct