제출 #1291916

#제출 시각아이디문제언어결과실행 시간메모리
1291916thaibeo123Stove (JOI18_stove)C++20
100 / 100
14 ms1480 KiB
#include <bits/stdc++.h>
using namespace std;

#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 1e5 + 5;

int n, k;
int a[N];
vector<int> v;

void input() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
}

void solve() {
    int ans = a[n] - a[1] + 1;
    for (int i = 2; i <= n; i++) {
        v.pb(a[i] - a[i - 1] - 1);
    }
    k--;
    sort(all(v), greater<>());
    for (int i = 0; i < k; i++) {
        ans -= v[i];
    }
    cout << ans;
}

signed main() {
    if (fopen(NAME".INP", "r")) {
        freopen(NAME".INP", "r", stdin);
        freopen(NAME".OUT", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    input();
    solve();

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'int main()':
stove.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(NAME".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(NAME".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...