Submission #207531

#TimeUsernameProblemLanguageResultExecution timeMemory
207531LightningStove (JOI18_stove)C++14
100 / 100
32 ms2292 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #include <cassert> #include <stack> #include <queue> #include <deque> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef pair <int, int> pii; // template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define ppb pop_back #define mkp make_pair #define F first #define S second #define show(a) cerr << #a <<" -> "<< a <<"\n" #define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d)) #define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d)) //#define int ll const int N = 2e5 + 5; const int INF = 1e9 + 5; int n, k, ans, t[N]; vector <int> vec; void solve() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> t[i]; if (1 <= i-1) vec.pb(t[i] - (t[i-1]+1)); } int ans = t[n] + 1 - t[1]; sort(all(vec)); reverse(all(vec)); for (int i = 0; i < k-1; ++i) { ans -= vec[i]; } cout << ans; } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt = 1; while (tt --) { solve(); } return 0; } /* If you only do what you can do, You will never be more than you are now! */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...