Submission #1099959

#TimeUsernameProblemLanguageResultExecution timeMemory
1099959Trn115Stove (JOI18_stove)C++11
100 / 100
15 ms3028 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define all(v) v.begin(), v.end() using namespace std; inline void setio(string name = "") { cin.tie(0)->sync_with_stdio(0); if (fopen((name+".INP").c_str(), "r")) { freopen((name+".INP").c_str(), "r", stdin); freopen((name+".OUT").c_str(), "w", stdout); } } int n, k; vector<int> t; inline void input() { cin >> n >> k; t.resize(n); for (int &i : t) cin >> i; } inline void solve() { vector<int> g(n-1); for (int i = 0; i < n-1; ++i) g[i] = t[i+1] - t[i] - 1; int total = t.back() - t.front() + 1; sort(all(g), greater<int>()); cout << total - accumulate(g.begin(), g.begin()+(k-1), 0); } signed main() { setio(); input(); solve(); }

Compilation message (stderr)

stove.cpp: In function 'void setio(std::string)':
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((name+".INP").c_str(), "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((name+".OUT").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...