Submission #792435

#TimeUsernameProblemLanguageResultExecution timeMemory
792435vjudge1Stove (JOI18_stove)C++17
0 / 100
1 ms212 KiB
#ifdef Home #define _GLIBCXX_DEBUG #endif // Home #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; main() { #ifdef Home freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // Home ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector < int > a(n); for(auto &i : a) { cin >> i; } ll l = 0, r = 1e9, m, t; for(; l + 1 < r;) { m = (l + r) / 2; t = 1; for(int i = 1, j = 0; i < n; ++ i) { if(a[i] - a[j] + 1 > m) { ++ t; j = i; } } (t > k ? l : r) = m; } ll ans = 0, i = 1, j = 0; for(; i < n; ++ i) { if(a[i] - a[j] + 1 > r) { ans += a[i - 1] - a[j] + 1; j = i; } } cout << ans + (a.back() - a[j] + 1); }

Compilation message (stderr)

stove.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...