Submission #330744

# Submission time Handle Problem Language Result Execution time Memory
330744 2020-11-26T12:52:11 Z M_W Stove (JOI18_stove) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int, int>
struct cmp{
	bool operator()(const ii &a, const ii &b) const{
		return abs(a.first - a.second) < abs(b.first - b.second);
	}
};
int g[100100];
int main(){
	priority_queue<ii, vector<ii>, cmp> pq;
	int N, K, cur, old, maxt = INT_MIN;
	scanf("%d %d", &N, &K);
	for(int i = 0; i < N; i++){
		scanf("%d", &g[i]);
	}
	sort(g, g + N);
	old = g[0];
	for(int i = 1; i < N; i++){
		pq.push(make_pair(old + 1, g[i]));
		old = g[i];
		maxt = max(maxt, g[i] + 1);
	}
	K--;
	vector<int> v;
	while(!pq.empty() && K > 0){
		int s = pq.top().first;
		int e = pq.top().second;
		pq.pop();
		
		v.push_back(s);
		v.push_back(e);
		K--;
	}
	v.push_back(1);
	v.push_back(maxt);
	sort(v.begin(), v.end());
	int sz = v.size();
	int tuse = 0;
	for(int i = 0; i < sz; i += 2){
		tuse += v[i + 1] - v[i];
	}
	printf("%d", tuse);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:12:12: warning: unused variable 'cur' [-Wunused-variable]
   12 |  int N, K, cur, old, maxt = INT_MIN;
      |            ^~~
stove.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |  scanf("%d %d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   scanf("%d", &g[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -