Here is my code:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define all(x) begin(x), end(x)
#define dbg(x) for(auto& a: x) cout << a << " "
#define re(x) cin >> x
#define print(x) cout << x << endl;
#define sort(x) sort(all(x))
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ROF(i, b, a) for(int i=(b)-1; i>=a; --i)
int main(){
int n, k; re(n); re(k);
// Read in how many years before the current year (2021?) each ancestor lived...
vl yearsBefore(n);
FOR(i, 0, n){
re(yearsBefore[i]);
}
// Find which portal interval each ancestor is a part of...
FOR(i, 0, n){
yearsBefore[i] = (yearsBefore[i] / 12);
}
sort(yearsBefore);
// dbg(yearsBefore);
// print("");
vl differences(n);
differences[0] = 0;
FOR(i, 1, n){
differences[i] = yearsBefore[i] - yearsBefore[i-1];
}
// dbg(differences);
// print("");
ll sumX = 0;
sort(differences);
FOR(i, 0, (differences.size() - (k-2))){
sumX += (differences[i]);
}
print((sumX + (k-1)) * 12);
}
Could someone help me identify what’s wrong with my code?
USACO servers say that I got 1/10 test cases from this solution…