Submission #657718

#TimeUsernameProblemLanguageResultExecution timeMemory
657718_Knyaz_Stove (JOI18_stove)C++17
100 / 100
19 ms2844 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define all(x) (x).begin(),(x).end() const int mod = 1e9+7; const double PI = acos( -1. ); void in(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int fenwick(vector<int> &vec, int i){ int sum = 0; while(i > 0){ sum += vec[i]; i -= i & -i; } return sum; } void solve(){ //in(); int n, k; cin >> n >> k; vector<int> vec(n), ans(n - 1); for(auto &x:vec) cin >> x; sort(all(vec)); for(int i = 1; i < n; i++) ans[i-1] = vec[i] - vec[i-1] - 1; sort(all(ans)); int res = vec[n-1] - vec[0] + 1; for(int i = n - 2; i > n - k - 1; i--) res -= ans[i]; cout << res; } signed main(){ cin.tie(0)->sync_with_stdio(0); int t; t = 1; //cin >> t; while(t--) solve(); } /* ██╗ ██╗███╗ ██╗██╗ ██╗ █████╗ ███████╗ ██║ ██╔╝████╗ ██║╚██╗ ██╔╝██╔══██╗╚══███╔╝ █████╔╝ ██╔██╗ ██║ ╚████╔╝ ███████║ ███╔╝ ██╔═██╗ ██║╚██╗██║ ╚██╔╝ ██╔══██║ ███╔╝ ███████╗██║ ██╗██║ ╚████║ ██║ ██║ ██║███████╗███████╗ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝ */

Compilation message (stderr)

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