Submission #571230

#TimeUsernameProblemLanguageResultExecution timeMemory
571230YouAreMyGalaxyStove (JOI18_stove)C++17
100 / 100
25 ms2144 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5; int a[N + 1], b[N + 1], n, k; int res; void read() { cin >> n >> k; for (int i = 1; i <= n; ++ i) { cin >> a[i]; } } void solve() { for (int i = 2; i <= n; ++ i) { b[i] = a[i] - 1 - a[i - 1]; } sort(b + 2, b + n + 1); res = a[n] + 1 - a[1]; for (int i = n; i >= n - k + 2; -- i) { res -= b[i]; } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

Compilation message (stderr)

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