답안 #811034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
811034 2023-08-06T21:50:40 Z manhlinh1501 Stove (JOI18_stove) C++17
0 / 100
2 ms 340 KB
/// @author : Hoang Manh Linh
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
using i64 = long long;

#define eb emplace_back
#define all(a) a.begin(), a.end()

int TC;
int n, k;
i64 a[MAXN];

int main(int argc, char **argv) {
    if(fopen(".inp", "r")) {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }

#ifndef ONLINE_JUDGE
    freopen("test.inp", "r", stdin);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    TC = 1;

    while(TC--) {
        cin >> n >> k;

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

        vector<i64> res;

        for(int i = 2; i <= n; i++)
            res.eb(a[i] - a[i - 1] - 1);

        sort(all(res));
        reverse(all(res));
        i64 ans = a[n];

        for(int i = 0; i < k - 1; i++)
            ans -= res[i];

        cout << ans << "\n";
    }
}

Compilation message

stove.cpp: In function 'int main(int, char**)':
stove.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
stove.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
stove.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("test.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -