# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1208170 | lmtonay | Stove (JOI18_stove) | C++17 | 1 ms | 320 KiB |
#include <bits/stdc++.h>
using namespace std;
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL);
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#ifndef ONLINE_JUDGE
#define debug(x) \
cerr << #x << " = "; \
_print(x); \
cerr << endl;
#else
#define debug(x)
#endif
void _print(int x) { cerr << x; }
void _print(long x) { cerr << x; }
void _print(ll x) { cerr << x; }
void _print(unsigned x) { cerr << x; }
void _print(unsigned long x) { cerr << x; }
void _print(unsigned long long x) { cerr << x; }
void _print(float x) { cerr << x; }
void _print(double x) { cerr << x; }
void _print(long double x) { cerr << x; }
void _print(char x) { cerr << '\'' << x << '\''; }
void _print(const string &x) { cerr << '"' << x << '"'; }
void _print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void _print(const pair<T, V> &p)
{
cerr << '{';
_print(p.first);
cerr << ", ";
_print(p.second);
cerr << '}';
}
template <typename T>
void _print(const vector<T> &v)
{
cerr << "[ ";
for (const auto &i : v)
{
_print(i);
cerr << " ";
}
cerr << "]";
}
template <typename T>
void _print(const set<T> &v)
{
cerr << "{ ";
for (const auto &i : v)
{
_print(i);
cerr << " ";
}
cerr << "}";
}
template <typename T>
void _print(const multiset<T> &v)
{
cerr << "{ ";
for (const auto &i : v)
{
_print(i);
cerr << " ";
}
cerr << "}";
}
template <typename T>
void _print(const unordered_set<T> &v)
{
cerr << "{ ";
for (const auto &i : v)
{
_print(i);
cerr << " ";
}
cerr << "}";
}
template <typename T, typename V>
void _print(const map<T, V> &v)
{
cerr << "{ ";
for (const auto &i : v)
{
_print(i);
cerr << " ";
}
cerr << "}";
}
template <typename T>
void _print(const vector<vector<T>> &v)
{
cerr << "[\n";
for (const auto &row : v)
{
cerr << " ";
_print(row);
cerr << "\n";
}
cerr << "]";
}
int main()
{
fast_io;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
int nums[n + 1] = {0};
for (int i = 1; i <= n; i++)
{
cin >> nums[i];
}
int diff[n] = {0};
for (int i = 1; i < n; i++)
{
diff[i] = nums[i + 1] - nums[i];
}
sort(diff, diff + n);
ll sum = 0;
for (int i = 0; i < k; i++)
{
sum += diff[i] + 1;
}
cout << sum << endl;
return 0;
}
Compilation message (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... |