Submission #1151204

#TimeUsernameProblemLanguageResultExecution timeMemory
1151204vyaductStove (JOI18_stove)C++20
100 / 100
30 ms1096 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> oset;

void setIo(string in="", string out=""){
  if (!in.empty() && !out.empty()){
    freopen(in.c_str(), "r", stdin);
    freopen(out.c_str(), "w", stdout);
  }
  ios::sync_with_stdio(false);
  cin.tie(0);
}

#define all(c)      (c).begin(), (c).end()
#define sz(c)       (int)(c).size()
#define vt          vector
#define pb          push_back
#define F           first
#define S           second
#define pii         pair<int, int>
#define DEBUG       true
#define dbg(x)      if (DEBUG) cout << #x << " = " << x << ";\n";
#define dbg_vec(v)  if (DEBUG) cout << #v << " = { "; for (auto x: v) {cout << x << " ";} cout << "};\n";

void solve() {
  int n,k; cin>>n>>k;
  vt<int> T(n);
  for (int i=0;i<n;i++) cin>>T[i];
  vt<int> aux(n-1);
  for (int i=0;i<n-1;i++){
    aux[i] = T[i+1]-T[i];
  }
  sort(all(aux));
  for (int i=0;i<k-1;i++) aux.pop_back();

  int s=0;
  for (int x: aux){
    s+=x;
  }
  cout << s+k << endl;


} 

int main() {
  int tt = 1; 
  // cin >> tt; 
  while (tt--) solve();
  return 0;
}

Compilation message (stderr)

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