Submission #330020

#TimeUsernameProblemLanguageResultExecution timeMemory
330020sazid_alamStove (JOI18_stove)C++17
100 / 100
25 ms3200 KiB
//Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pair<int, int>> vpi; #define pb push_back #define pf push_front #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define ff first #define ss second #define mp make_pair #define lb lower_bound #define ub upper_bound #define Tcase() int t; cin >> t; while(t--) #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define F0R(i, a) FOR(i, 0, a) const ll MOD = 1e9 + 7; //998244353; const ll INF = 1e18; const int MX = 2e5 + 5; const ld PI = acos((ld) -1); const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if(sz(name)){ freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } int main(){ setIO(); ll n, k; cin >> n >> k; ll a[n] = {0}; F0R(i, n) cin >> a[i]; sort(a, a + n); vector<ll> Diff; FOR(i, 1, n) Diff.pb(a[i] - a[i - 1]); sort(all(Diff)); ll Ans = n; F0R(i, n - k) Ans += Diff[i] - 1; cout << Ans; }

Compilation message (stderr)

stove.cpp: In function 'void setIO(std::string)':
stove.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...