Submission #208708

#TimeUsernameProblemLanguageResultExecution timeMemory
208708tushar_2658Stove (JOI18_stove)C++14
0 / 100
5 ms376 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 100005; using ll = long long; ll a[maxn]; int n, k; ll mn = 1e18; bool can(ll x){ ll ret = 0; int cnt = 0; for(int i = 1; i <= n;){ ll l = a[i]; int j = i + 1; while(j <= n && a[j] - l + 1 <= x){ ++j; } ret += a[j - 1] - l + 1; cnt++; i = j; } mn = ret; return (cnt <= k); } int main(int argc, char const *argv[]) { // freopen("in.txt", "r", stdin); scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++){ scanf("%lld", &a[i]); } sort(a + 1, a + n + 1); ll lo = 1, hi = 1e18, ans = -1; while(lo <= hi){ ll mid = (lo + hi) >> 1; if(can(mid)){ ans = mid; hi = mid - 1; }else { lo = mid + 1; } } can(ans); cout << mn << endl; return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main(int, const char**)':
stove.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &a[i]);
     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...