Submission #1251542

#TimeUsernameProblemLanguageResultExecution timeMemory
1251542tradzStove (JOI18_stove)C++20
100 / 100
12 ms1480 KiB
#include <bits/stdc++.h> #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #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 ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long GetRandom(long long l, long long r) { return uniform_int_distribution<long long> (l, r)(rng); } int n, k, a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n >> k; For (i, 1, n) cin >> a[i]; sort (a + 1, a + n + 1); ll ans = 0; int num = n; vector <int> b; for (int i = 1; i < n; i++) b.push_back(a[i + 1] - a[i]); sort (all(b)); for (auto x: b) { if (num == k) break; ans += x; num--; } cout << ans + k << '\n'; cerr << "Time elapsed: " << TIME << " s.\n"; return 0; }

Compilation message (stderr)

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