Submission #1228810

#TimeUsernameProblemLanguageResultExecution timeMemory
1228810khoinguStove (JOI18_stove)C++20
0 / 100
0 ms328 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; bool vis[maxN]; 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]; vis[t[i] + 1] = true; } ans = t[n] + 1 - t[1]; int cnt = 0; for(int i = 1; i <= t[n] + 1; i ++) { if (!vis[i]) cnt ++; else { if (cnt != 0) { tim.push_back(cnt); cnt = 0; } } } sort(tim.rbegin(), tim.rend()); //for(auto x : tim) cout << x << ' '; k --; while (k > 0 and !tim.empty()) { ans -= tim[0]; //cout << tim[0] << " "; tim.erase(tim.begin()); k --; } cout << ans; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
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.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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("task.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...