CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:muhk3l1
Submission time:2018-10-03 14:23:03 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (k >= erilaiset.size()) {
      ~~^~~~~~~~~~~~~~~~~~~
input/code.cpp:25:31: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
   e = abs(erilaiset.size() - k);
                               ^
In file included from /usr/include/c++/7/bits/std_abs.h:38:0,
                 from /usr/include/c++/7/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from input/code.cpp:1:
/usr/include/stdlib.h:837:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/include/c++/7/cmath:47:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/std_abs.h:56:3: note: candidate: long int std::abs(long int)
   abs(...

Code

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, k, x, v = 0, e;
	vector<ll> taulukko;
	set<ll> erilaiset;
	cin >> n >> k;

	for (ll i = 0; i < n; i++) {
		cin >> x;
		taulukko.push_back(x);
		erilaiset.insert(x);
	}
	if (k >= erilaiset.size()) {
		for (ll i = 1; i <= n; i++) {
			v += i;
		}
		cout << v;
		return 0;
	} else {
		e = abs(erilaiset.size() - k);
		for (ll i = 1; i <= n - e; i++) {
			v += i;
		}
		cout << v;
		return 0;
	}

}