Submission #59948

# Submission time Handle Problem Language Result Execution time Memory
59948 2018-07-23T11:10:14 Z gusfring Stove (JOI18_stove) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

const int MAXN = 1e5 + 5;

int t[MAXN], a[MAXN], N, K;

int main(){
	int N, K;
	scanf("%d %d", &N, &K);
	for(int i=0; i<n; ++i) scanf("%d", &t[i]);
	int res = t[n - 1] + 1 - t[0];
	for(int i=0; i<n-1; ++i) a[i] = t[i + 1] - t[i] - 1;
	std::sort(a, a + n - 1, std::greater<int>());
	for(int i=0; i<k-1; ++i) res -= a[i];
	printf("%d",res);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:10:17: error: 'n' was not declared in this scope
  for(int i=0; i<n; ++i) scanf("%d", &t[i]);
                 ^
stove.cpp:11:14: error: 'n' was not declared in this scope
  int res = t[n - 1] + 1 - t[0];
              ^
stove.cpp:14:17: error: 'k' was not declared in this scope
  for(int i=0; i<k-1; ++i) res -= a[i];
                 ^
stove.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:10:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<n; ++i) scanf("%d", &t[i]);
                         ~~~~~^~~~~~~~~~~~~