# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1272260 | jungle15 | Stove (JOI18_stove) | C++17 | 14 ms | 832 KiB |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define Jungle "JOI18_stove"
#define getbit(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1 << (i))
#define cntbit __builtin_popcount
#define MULTEST \
int nq; \
cin >> nq; \
while(nq--)
template <typename t> void chkmin(t &a, t b)
{
if(a > b) a = b;
}
template <typename t> void chkmax(t &a, t b)
{
if(a < b) a = b;
}
const int mod = 1e9 + 7;
int add(int a, int b)
{
return (1ll * a + b) % mod;
}
int sub(int a, int b)
{
return (1ll * a - b + mod) % mod;
}
int mul(int a, int b)
{
return 1ll * a * b % mod;
}
const int maxn = 1e5;
int n, nk, a[maxn + 2];
void init(void)
{
cin >> n >> nk;
for(int i = 1; i <= n; i++)
cin >> a[i];
}
int res;
void solve(void)
{
init();
sort(a + 1, a + n + 1);
res = a[n] + 1 - a[1];
for(int i = 1; i < n; i++)
a[i] = a[i + 1] - a[i] - 1;
sort(a + 1, a + n);
for(int i = n - 1; nk > 1; i--, nk--)
res -= a[i];
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
if(fopen(Jungle".inp", "r"))
{
freopen(Jungle".inp", "r", stdin);
freopen(Jungle".out", "w", stdout);
}
// MULTEST
solve();
// cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
컴파일 시 표준 에러 (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... |