Submission #307210

#TimeUsernameProblemLanguageResultExecution timeMemory
307210cpp219Stove (JOI18_stove)C++14
100 / 100
22 ms1312 KiB
// Solid <candgenesis> #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 3e5 + 4; const ll inf = 1e9 + 7; const ll base = 37; typedef pair<ll,ll> LL; ll n,k,a[N],i,b[N]; bool lf(ll x,ll y){ return x > y; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n>>k; k--; for (i = 1;i <= n;i++) cin>>a[i]; for (i = 1;i < n;i++) b[i] = a[i + 1] - a[i] - 1; sort(b + 1,b + n,lf); ll ans = a[n] - a[1] + 1; for (i = 1;i < n;i++){ if (k) ans -= b[i],k--; else break; } cout<<ans; }

Compilation message (stderr)

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