Submission #1228812

#TimeUsernameProblemLanguageResultExecution timeMemory
1228812khoinguStove (JOI18_stove)C++20
100 / 100
12 ms1480 KiB
#include <bits/stdc++.h> #define ll long long #define fi(i,a,b) for(int i = a; i <= b; i ++) using namespace std; const ll maxN = 1e5 + 5; int n, k, t[maxN], ans = 0; vector <int> tim; signed main() { if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; i ++) { cin >> t[i]; } ans = t[n] + 1 - t[1]; for(int i = 2; i <= n; i ++) { tim.push_back(t[i] - t[i - 1] - 1); } sort(tim.rbegin(), tim.rend()); //for(auto x : tim) cout << x << ' '; //k --; for(int i = 0; i < k - 1 and i < tim.size(); i ++) { ans -= tim[i]; } cout << ans; }

Compilation message (stderr)

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