Submission #931887

# Submission time Handle Problem Language Result Execution time Memory
931887 2024-02-22T14:09:43 Z lovrot Stove (JOI18_stove) C++17
0 / 100
1 ms 348 KB
#include <cstdio> 
#include <algorithm> 
#include <cstring> 
#include <cmath> 
#include <iostream> 
#include <set> 
#include <queue> 
#include <deque> 
#include <vector> 
#include <random> 
#include <chrono> 

#define X first
#define Y second
#define PB push_back
#define EB emplace_back

using namespace std; 

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MOD = 1e9 + 7; // 998 244 353;
const int N = 1e5 + 10;

int n, k, A[N];

int main() {
	scanf("%d%d", &n, &k); 
	int lst = 0, ans = 0;
	for(int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x); 
		A[i] = x - lst - 1;
		if(!i) ans -= x;
		if(i == n - 1) ans += x + 1;
		lst = x;
	}
	sort(A + 1, A + n, [](int a, int b) { return a > b; });
	for(; k--; ) ans -= A[k];
	printf("%d\n", ans);
	return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -