답안 #982327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982327 2024-05-14T06:40:04 Z Amirreza_Fakhri Stove (JOI18_stove) C++17
100 / 100
36 ms 6736 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, t[maxn];
multiset <int, greater <int> > st;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        if (i) st.insert(-t[i]+t[i-1]);
    }
    int ans = k-t[0]+t[n-1];
    while (st.size() >= k) st.erase(st.begin());
    for (auto it = st.begin(); it != st.end(); it++) ans += *it;
    cout << ans << '\n';
    return 0;
}





/*
srand(time(0));
cout << (rand()%1900) + 1 << ' ' << (rand()%2)+5 << '\n';
*/






















Compilation message

stove.cpp: In function 'int32_t main()':
stove.cpp:35:22: warning: comparison of integer expressions of different signedness: 'std::multiset<int, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |     while (st.size() >= k) st.erase(st.begin());
      |            ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 29 ms 6492 KB Output is correct
17 Correct 29 ms 6484 KB Output is correct
18 Correct 36 ms 6484 KB Output is correct
19 Correct 28 ms 6484 KB Output is correct
20 Correct 29 ms 6480 KB Output is correct
21 Correct 29 ms 6492 KB Output is correct
22 Correct 30 ms 6736 KB Output is correct
23 Correct 29 ms 6488 KB Output is correct
24 Correct 30 ms 6492 KB Output is correct