Submission #1241941

#TimeUsernameProblemLanguageResultExecution timeMemory
1241941hanguyenStove (JOI18_stove)C++20
100 / 100
13 ms2244 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn = 1e5 + 5 ; int n , k; int a[maxn]; vector<int>res; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for(int i = 1; i < n; i++) { int diff = a[i + 1] - a[i] - 1; res.push_back(diff); } sort(res.begin(),res.end()); int ans = n; for(int i = 0; i < n - k; i++) ans += res[i]; cout << ans; }

Compilation message (stderr)

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