답안 #943561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943561 2024-03-11T15:19:51 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
16 ms 2304 KB
# include <bits/stdc++.h>

# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
# define pii pair <int, int>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll maxn = (ll)1e5 + 3;
const ll inf  = (ll)2e18 + 0;
const ll mod  = (ll)1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
const bool T = 0;

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

void Freopen () {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int n, k, t[maxn];

void ma1n () {
    cin >> n >> k;
    vector <int> e;
    for (int i = 1; i <= n; ++i) {
        cin >> t[i];
        if (i > 1) e.pb(t[i] - t[i - 1] - 1);
    }
    sort(e.rbegin(), e.rend());
    int ans = t[n] + 1 - t[1];
    for (int i = 0; i < min(sz(e), k - 1); ++i) ans -= e[i];
    cout << ans << nl;
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // Freopen();
    int ttt = 1;
    if (T) cin >> ttt;
    for (int test = 1; test <= ttt; ++test) {
//      cout << "Case " << test << ":" << '\n';
        ma1n();
    }
    return 0;
}

Compilation message

stove.cpp: In function 'void Freopen()':
stove.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 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 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 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 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 16 ms 2204 KB Output is correct
17 Correct 14 ms 2304 KB Output is correct
18 Correct 14 ms 2268 KB Output is correct
19 Correct 14 ms 2268 KB Output is correct
20 Correct 14 ms 2240 KB Output is correct
21 Correct 14 ms 2268 KB Output is correct
22 Correct 14 ms 2272 KB Output is correct
23 Correct 15 ms 2268 KB Output is correct
24 Correct 14 ms 2268 KB Output is correct