Submission #1268784

#TimeUsernameProblemLanguageResultExecution timeMemory
1268784bgnbvnbvStove (JOI18_stove)C++20
100 / 100
14 ms2248 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define st first
#define nd second
#define pb push_back
#define endl '\n'
#define task "revenue"

using pii = pair<int,int>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAXN =5e3 + 5;
const int MAXK = 110;
const int LOG = 20;




int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	
	if (fopen(task".inp","r")) {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    
    
    
    int n,k; cin >> n >> k;
    
    vector <int> t(n);
    
    for(int i=0;i<n;++i){
    	cin >> t[i];
    }
	
	int total = t[n-1] - t[0] + 1;
	
	vector <int> gap;
	
	for(int i=0;i < n - 1;++i){
		int g = t[i+1] - (t[i] + 1);
		gap.pb(g);
	}
	
	sort(gap.rbegin(),gap.rend());
	
	for(int i=0;i < k -1 and i < (int)gap.size();++i){
		total -= gap[i];
	}
	
	
	cout << total << endl;
	
    return 0;
}
	

Compilation message (stderr)

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