Submission #966456

#TimeUsernameProblemLanguageResultExecution timeMemory
966456AliyyiakbarStove (JOI18_stove)C++17
100 / 100
18 ms4056 KiB
#include <iostream> #include <algorithm> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/hash_policy.hpp> #define int long long #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #define pb push_back #define ep emplace_back #define all(v) v.begin(),v.end() #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_set; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_multiset; const int sz = 3e5+9; const int MOD = 1e9+7; const int INF = 1e18; int a[sz]; int n,k; void solve() { cin>>n>>k; --k; vector<int>v; int res = n; for (int i = 1; i <= n; ++i) { cin>>a[i]; if (i > 1) v.ep(a[i]-(a[i-1]+1)), res += v.back(); //cerr<<"emplaced: "<<(max(0LL,(a[i]-(a[i-1]+1))))<<'\n'; } sort(all(v)); while(!v.empty() && k) { res -= v.back(); //cerr<<"pop: "<<(int)v.back()<<'\n'; v.pop_back(); --k; } cout<<res<<'\n'; } signed main() { $AzH_TxdmN$ int t = 1; //cin>>t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...