Submission #1102464

#TimeUsernameProblemLanguageResultExecution timeMemory
1102464sktodowStove (JOI18_stove)C++17
100 / 100
18 ms3164 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define pb push_back #define mid a+(b-a)/2 const int N=5e5+5; const int MOD=1e9+7; const int inf=2e18+5; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; void io(string name = ""){ freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin>>n>>k; vector<int>arr(n); for(auto &a:arr){cin>>a;} sort(arr.begin(),arr.end()); vector<int>dis; for(int i=1;i<n;i++){ dis.pb(arr[i]-arr[i-1]-1); } sort(dis.rbegin(),dis.rend()); int ans=0; for(int i=0;i<min(k-1,(int)dis.size());i++){ ans+=dis[i]; } cout<<arr[n-1]-arr[0]+1-ans; return 0; }

Compilation message (stderr)

stove.cpp: In function 'void io(std::string)':
stove.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((name+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((name+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...