Compile Error
foo.cc: In function 'int main()': foo.cc:9:9: error: 'vector' was not declared in this scope 9 | vector<long long> A(N); | ^~~~~~ foo.cc:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'? 1 | #include <iostream> +++ |+#include <vector> 2 | using namespace std; foo.cc:9:16: error: expected primary-expression before 'long' 9 | vector<long long> A(N); | ^~~~ foo.cc:10:44: error: 'A' was not declared in this scope 10 | for (int i = 0; i < N; i++) cin >> A[i]; | ^ foo.cc:11:14: error: 'A' was not declared in this scope 11 | sort(A.rbegin(), A.rend()); | ^ foo.cc:11:9: error: 'sort' was not declared in this scope; did you mean 'short'? 11 | sort(A.rbegin(), A.rend()); | ^~~~ | short
Code
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while (T--) {
int N; cin >> N;
vector<long long> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
sort(A.rbegin(), A.rend());
long long S = 0;
for (int i = 0; i < N; i++) {
if (i % 2 == 0)
S += A[i];
else
S -= A[i];
}
cout << S << "\n";
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1208 C. Game on Integer
- Contest
- Educational Round 1
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-07-14 16:10:19
- Judged At
- 2025-07-14 16:10:19
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes