Submission #943561

#TimeUsernameProblemLanguageResultExecution timeMemory
943561vjudge1Stove (JOI18_stove)C++17
100 / 100
16 ms2304 KiB
# include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) # define all(x) (x).begin(), (x).end() # define deb(x) cerr << #x << " = " << x << endl; # define pll pair <ll, ll> # define pii pair <int, int> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = (ll)1e5 + 3; const ll inf = (ll)2e18 + 0; const ll mod = (ll)1e9 + 7; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; const bool T = 0; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void Freopen () { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int n, k, t[maxn]; void ma1n () { cin >> n >> k; vector <int> e; for (int i = 1; i <= n; ++i) { cin >> t[i]; if (i > 1) e.pb(t[i] - t[i - 1] - 1); } sort(e.rbegin(), e.rend()); int ans = t[n] + 1 - t[1]; for (int i = 0; i < min(sz(e), k - 1); ++i) ans -= e[i]; cout << ans << nl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // Freopen(); int ttt = 1; if (T) cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << '\n'; ma1n(); } return 0; }

Compilation message (stderr)

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