Submission #668749

#TimeUsernameProblemLanguageResultExecution timeMemory
668749mseebacherStove (JOI18_stove)C++17
100 / 100
18 ms2308 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
 
void setIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".ans").c_str(), "w", stdout);
}              
 
#define MAXI (int)1e5
#define LSOne(S) ((S) & -(S))
#define MSB(S) __builtin_clz(S)
 
void solve(){
		 
		 int n,k; cin >> n >> k;
		 int b[n];
		 for(int i = 0;i<n;i++){
			cin >> b[i];
		 }
		 ll dis = b[n-1]-b[0]+1;
		 vector<int> diff;
		 for(int i = 1;i<n;i++){
				diff.push_back(b[i]-b[i-1]-1);
		 }
		 sort(diff.rbegin(),diff.rend());
		 for(int i = 0;i+1<k;i++){
			dis -= diff[i];
	     }
	     cout << dis;
}
 
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout << fixed << setprecision(8);
 
   int t = 1;
   //cin >> t;
   while(t){
	solve();
	t--;  
	cout << "\n";
   }
}

Compilation message (stderr)

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