Submission #1209773

#TimeUsernameProblemLanguageResultExecution timeMemory
1209773nvc2k8Stove (JOI18_stove)C++20
100 / 100
12 ms1096 KiB
#include <bits/stdc++.h> #define TASK "aksdjkasdj" #define INT_LIM (int) 2147483647 #define LL_LIM (long long) 9223372036854775807 #define endl '\n' #define mp make_pair #define pb push_back #define fi first #define se second #define BIT(i,x) (((i)>>(x))&1) #define FOR(i,a,b) for(int i = (a); i<=(b); i++) #define FORD(i,a,b) for(int i = (a); i>=(b); i--) #define ll long long #define pii pair<int,int> using namespace std; ///------------------------------------------/// int n,k; int a[100005]; int ans = 0; vector<int> f; void inp() { cin >> n >> k; f.reserve(100000); FOR(i, 1, n) cin >> a[i]; ans = a[n]+1-a[1]; FOR(i, 1, n-1) { f.pb(a[i+1]-a[i]-1); } } void solve() { sort(f.begin(), f.end(), greater<int>()); FOR(i, 1, k-1) ans-=f[i-1]; cout << ans; } signed main() { ///--------------------------/// ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen(TASK".INP","r")!=NULL) { freopen(TASK".INP","r",stdin); freopen(TASK".OUT","w",stdout); } ///--------------------------/// int NTEST = 1; //cin >> NTEST; while (NTEST--) { inp(); solve(); } return 0; } ///------------------------------------------///

Compilation message (stderr)

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