답안 #875131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875131 2023-11-18T17:36:39 Z misu2005 Stove (JOI18_stove) C++11
100 / 100
73 ms 4592 KB
#include <iostream>
#include <map>

using namespace std;

int n, k, v[100002];
map<int, int> fr1, fr2;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i];
        if (i >= 2) {
            fr1[-v[i] + v[i-1]]++;
        }
    }

    k--;
    for (auto it:fr1) {
        if (!k)
            break;
        if (it.first == -1)
            continue;
        fr2[it.first] += min(it.second, k);
        k -= min(it.second, k);
    }

    int timp = 1;
    for (int i = 2; i <= n; i++) {
        if (v[i] - v[i-1] == 1)
            timp++;
        else {
            if (fr2[-v[i]+v[i-1]] == 0) {
                timp += v[i] - v[i-1];
            }
            else {
                fr2[v[i-1]-v[i]]--;
                timp++;
            }
        }
    }
    cout << timp;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 57 ms 4424 KB Output is correct
17 Correct 58 ms 4592 KB Output is correct
18 Correct 65 ms 4432 KB Output is correct
19 Correct 58 ms 4436 KB Output is correct
20 Correct 65 ms 4432 KB Output is correct
21 Correct 68 ms 4432 KB Output is correct
22 Correct 73 ms 4464 KB Output is correct
23 Correct 68 ms 4328 KB Output is correct
24 Correct 68 ms 4436 KB Output is correct