| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1350732 | phungmanager0 | Stove (JOI18_stove) | C++20 | 11 ms | 2248 KiB |
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define IS_INF(x) (std::isinf(x))
#define IS_NAN(x) (std::isnan(x))
#define fi first
#define se second
#define int long long
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define div ___div
#define prev ___prev
#define next ___next
#define left ___leftc
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define __Im_sogood__ main()
#define __builtin_popcount __builtin_popcountll
using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 1e18;
int n, k, t[MAXN];
void solve() {
cin >> n >> k; FOR(i, 1, n) cin >> t[i]; int ans = t[n] + 1 - t[1];
vector<int> f; FOR(i, 1, n - 1) f.push_back(t[i + 1] - t[i] - 1);
sort(ALL(f)); reverse(ALL(f)); FOR(i, 0, min(k - 2, n - 1)) {
ans -= max(f[i], 0ll);
} cout << ans;
}
__Im_sogood__{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
cerr << "Time elapsed: " << TIME << " s.\n";
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
