제출 #311476

#제출 시각아이디문제언어결과실행 시간메모리
311476MSAADStove (JOI18_stove)C++17
20 / 100
1 ms512 KiB
/* NAME: ___ _ _ ___ / __| /_\ /_\ | \ \__ \/ _ \ / _ \| |) | |___/_/ \_\/_/ \_\___/ lang: ___ _ _ / __)_| |_ _| |_ ( (__(_ _)(_ _) \___) |_| |_| */ #define _USE_MATH_DEFINES #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> using namespace std; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() typedef long long ll; typedef long l; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<l> vl; typedef vector<ll> vll; const int INF = 1 << 29; const int MOD = 1e9 + 7; const int dx[]={0,1,0,-1}; const int dy[]={1,0,-1,0}; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } void solve(){ int n,k; cin>>n>>k; ll a[n],b[n]; pair<ll,ll>p[n]; for(int i=0;i<n;i++) { cin>>b[i]; a[i]=b[i]; } p[0]=make_pair(b[0],0); for(int i=1;i<n;i++) p[i]=make_pair(b[i]-b[i-1],i); sort(p,p+n); for(int i=n-1;(i>=0 && k>1);(i-- && k--)){ // cout<<b[p[i].second]<< " "; b[p[i].second]=0; } //for(int i=1;i<n;i++) cout<<b[i]-b[i-1]<<" "; ll ans=1,cnt=0,j=1; while(j<n){ if(b[j]!=0 && j){ ans+=(a[j]-a[j-1]); cnt++; } else{ ans++; cnt=0; } // cout<<ans<<" "; j++; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...