| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1296393 | temurbek1371 | Stove (JOI18_stove) | C++20 | 14 ms | 2004 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_multiset = tree<
T,
null_type,
less_equal<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vb vector<bool>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define endl '\n'
#define maxx(x) *max_element(all(x))
#define pii pair<int,int>
#define minn(x) *min_element(all(x))
#define vpii vector<pii>
#define di deque<int>
#define mii map<int,int>
#define vap(x) vector<array<int,x>>
constexpr int MOD = 1000000007;
constexpr int inf = 1e18;
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
ostream& operator<<(ostream& out, vi& a) {
for (int i = 0; a.size() > i; i++)out << a[i] << ' ';
return out;
}
ostream& operator<<(ostream& out, vector<vi>& a) {
for (auto& row : a) {
for (auto& elem : row) out << elem << ' ';
out << '\n';
}
return out;
}
istream& operator>>(istream& in, vi& a) {
for (int i = 0; a.size() > i; i++) in >> a[i];
return in;
}
istream& operator>>(istream& in, vector<vi>& a) {
for(int i = 0;i<a.size();i++){
for(int j = 0;j<a[i].size();j++){
in >> a[i][j];
}
}
return in;
}
int sumofvecor(vi a){
int sm = 0;
for(int i = 0;i<a.size();i++)sm+=a[i];
return sm;
}
void file_io() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
pii getmax(vi a){
int n = a.size();
int mx = -inf,ans = 0;
for(int i = 0;i<n;i++){
if(mx<a[i]){
ans = i;
mx = a[i];
}
}
return {mx,ans};
}
bool isprime(int x){
for(int i = 2;i*i<=x;i++){
if(x%i==0)return false;
}
return x>=2;
}
int binpow(int base,int power){
int res = 1;
while(power>0){
if(power&1)res=(res*base)%MOD;
base = (base*base)%MOD;
power>>=1;
}
return res;
}
void solve();
signed main(signed argc, char *argv[]) {
clock_t start = clock();
fast_io();
// file_io();
if (argc > 1 && string(argv[1]) == "gg") file_io();
int test = 1;
// cin >> test;
while (test--) {
solve();
}
cerr << "Vaqt " << double(clock() - start) / double(CLOCKS_PER_SEC) * 1000 << " ms\n";
}
void solve(){
int n,k;
cin>>n>>k;
vi a(n);
cin>>a;
k--;
int ans = a[n-1]-a[0]+1;
vi diff(n-1);
for(int i = 0;i<n-1;i++){
diff[i]=a[i+1]-a[i]-1;
}
sort(allr(diff));
for(int i = 0;i<k;i++){
ans-=diff[i];
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (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... | ||||
