Submission #1270961

#TimeUsernameProblemLanguageResultExecution timeMemory
1270961nthvnStove (JOI18_stove)C++20
100 / 100
13 ms1096 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define pii pair<int,int> #define ll long long #define pb(x) push_back(x) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() const int N= 1e5+5; int n,k; int a[N], d[N]; signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); if(fopen("STOVE.INP", "r")){ freopen("STOVE.INP", "r", stdin); freopen("STOVE.OUT", "w", stdout); } cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<n;i++) d[i] = a[i]-a[i+1]; sort(d+1,d+n); ll ans = 0; for(int i=1;i<=k-1;i++) ans+= d[i]; ans+= -a[1] + a[n]+k; cout<<ans; }

Compilation message (stderr)

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