답안 #337093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337093 2020-12-18T10:13:40 Z deadeye Stove (JOI18_stove) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 69
#endif
template <typename Arg>
void __f(string name, Arg arg) {
	cerr << name << " = " << arg << endl;
}
template <typename Head, typename... Tail>
void __f(string names, Head head, Tail... tail) {
		string cur = "";
	for (auto ch: names){if(ch==','){break;}else{cur+=ch;}}
	string nxt = names.substr(cur.size()+2);
	cerr << cur << " = " << head << ", ";
	__f(nxt, tail...);
}

const int mxn = 100005;
int N, K, A[mxn], ans, idx = 1;
bool split[mxn];
vector<pi> d;

int query(int qs, int qe) {return A[qe] - A[qs] + 1;}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; ++i) cin >> A[i];
	for (int i = 2; i <= N; ++i) d.pb({A[i] - A[i - 1], i});
	sort(d.begin(), d.end(), greater<pi>());
	for (int i = 0; i < K - 1; ++i) split[d[i].si] = 1;
	for (int i = 1; i <= N; ++i) {
		if (split[i]) {
			ans += query(idx, i - 1);
			idx = i;
		}
	}
	if (K == 1) {
		cout << A[N] - A[1] + 1;
		return 0;
	}
	cout << ans + 1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -