Submission #1292968

#TimeUsernameProblemLanguageResultExecution timeMemory
1292968MinbaevStove (JOI18_stove)C++17
100 / 100
15 ms2256 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimize("Ofast,unroll-loops") using namespace std; using namespace __gnu_pbds; #define pb push_back #define all(x) x.begin(),x.end() #define int long long // #define double long double #define ar array #define mrand(a, b) uniform_int_distribution<int>(a, b)(rng) template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;} template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;} template<class T> using ste = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int binpow(int a, int b, int m){ if(b <= 0)return 1; if(b % 2 == 0){ int c = binpow(a,b/2,m); return (c*c)%m; } return (binpow(a,b-1,m)*a)%m; } int divi(int a, int b, int m){ return (a*(binpow(b,m-2, m)))%m; } struct modint { static int mod; long long val; modint(long long v = 0) { val = v % mod; if (val < 0) val += mod; } modint& operator+=(const modint& other) { val += other.val; if (val >= mod) val -= mod; return *this; } modint& operator+=(long long other) { return *this += modint(other); } modint& operator-=(const modint& other) { val -= other.val; if (val < 0) val += mod; return *this; } modint& operator-=(long long other) { return *this -= modint(other); } modint& operator*=(const modint& other) { val = (val * other.val) % mod; return *this; } modint& operator*=(long long other) { return *this *= modint(other); } modint& operator/=(const modint& other) { val = divi(val, other.val, mod); return *this; } modint& operator/=(long long other) { return *this /= modint(other); } friend modint operator+(modint a, const modint& b) { return a += b; } friend modint operator+(modint a, long long b) { return a += b; } friend modint operator+(long long a, modint b) { return b += a; } friend modint operator-(modint a, const modint& b) { return a -= b; } friend modint operator-(modint a, long long b) { return a -= b; } friend modint operator-(long long a, modint b) { return modint(a) -= b; } friend modint operator*(modint a, const modint& b) { return a *= b; } friend modint operator*(modint a, long long b) { return a *= b; } friend modint operator*(long long a, modint b) { return b *= a; } friend modint operator/(modint a, const modint& b) { return a /= b; } friend modint operator/(modint a, long long b) { return a /= b; } friend modint operator/(long long a, modint b) { return modint(a) /= b; } friend ostream& operator<<(ostream& os, const modint& m) { return os << m.val; } }; int modint::mod = 1e9 + 7; namespace FAST { template<typename T> istream &operator>>(istream &cin, vector<T> &a) { for (T &i: a) cin >> i; return cin; } template<typename T> ostream &operator<<(ostream &cout, vector<T> &a) { for (T i: a) cout << i << ' '; return cout; } } using namespace FAST; const int inf = 3e18 + 7; const int mod = 1e9 + 7; const int N = 6e5 + 5; const int md = 998244353; int rev(int a, int m){ if (a == 1)return 1; return (1 - rev(m % a, a) * m) / a + m; } struct Bit { vector<int> b, b2; int n; Bit(int n) { this->n = n + 1; b.assign(n + 1, 0); b2.assign(n+1, 0); } void add(vector<int>&b, int idx, int x){ while(idx <= n){ b[idx] += x; idx += idx & -idx; } } void upd(int l, int r, int x){ add(b, l, x); add(b, r+1, -x); add(b2, l, x*(l-1)); add(b2, r+1, -x*r); } int sum(vector<int>&b, int idx){ int res = 0; while(idx > 0){ res += b[idx]; idx -= idx & -idx; } return res; } int pref(int idx){ return sum(b, idx) * idx - sum(b2, idx); } int get(int l, int r){ return pref(r) - pref(l-1); } }; int n,m,k; void solve(){ cin >> n >> k; vector<int>v(n + 1); for(int i = 1;i<=n;i++)cin >> v[i]; v[0] = v[1]; //~ vector<vector<int>>dp(n + 1, vector<int>(k + 1, inf)); //~ dp[0][k] = 0; //~ for(int i = 1;i<=n;i++){ //~ if(i == 1){ //~ dp[i][k-1] = 1; //~ continue; //~ } //~ for(int j = k;j>=0;j--){ //~ int dist = v[i] - v[i-1]; //~ umin(dp[i][j], dp[i-1][j] + dist); //~ if(j < k) //~ umin(dp[i][j], dp[i-1][j + 1] + 1); //~ } //~ } //~ int res = inf; //~ for(int i = 0;i<=k;i++){ //~ umin(res, dp[n][i]); //~ } //~ cout << res << "\n"; vector<int>vs; for(int i = 2;i<=n;i++){ vs.pb(v[i] - v[i-1]); } sort(all(vs)); int res = n; for(int i = 0;i<n-k;i++){ res -= 1; res += vs[i]; } cout << res << "\n"; } /* */ signed main() { // freopen("seq.in", "r", stdin); // freopen("seq.out", "w", stdout); ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int tt=1;//cin >> tt; while(tt--)solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...