Submission #1295079

#TimeUsernameProblemLanguageResultExecution timeMemory
1295079dominus_ojStove (JOI18_stove)C++20
100 / 100
14 ms2432 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(s) s.begin(), s.end() #define endl '\n' #define pb(x) push_back(x) #define f first #define s second #define yes "YES" #define no "NO" #define sz(x) (int)x.size() typedef pair<int, int> pii; typedef vector<int> vi; const int mod = 1e9 + 7; const double EPS = 1e-7; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } void solve() { int n, k; cin >> n >> k; vi a(n); for (int i=0; i<n; i++) cin >> a[i]; vi b; for (int i=0; i<n-1; i++) { b.push_back(a[i+1] - a[i]); } sort(all(b)); int ans = 0; for (int i=0; i<n-k; i++) { ans += b[i]; } cout<<ans+k<<endl; } signed main() { // setIO(""); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); int t=1; while (t--) solve(); return 0; }

Compilation message (stderr)

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