I was making an algorithm to solve Problem 1310 from the URI Online Judge and at some point i needed to delete an item from an array in an easy way, so i declared a vector, but, besides having no issues running whatsoever, my code doesn´t print anything using , cout doesn´t work at all.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int Lucro(int c, int n, vector<int> r){
if (n == 0){
return 0;
}else if (n == 1){
return max(r[0] - c, 0);
}
int q;
q = 0;
for (int k = 0; k < n; k++){
r.erase(r.begin() + k);
q = max(q, r[k] - c + Lucro(c, n-1, r));
}
return q;
}
int main()
{
int C, N, items;
cin >> N >> C;
vector<int> R;
for (int i = 0; i < N; i++){
cin >> items;
R.push_back (items);
}
cout << Lucro(C, N, R) << endl;
cout << 'test' << endl;
}
As i´m quite new to using vectors in c++, could someone please explain to me what´s going on and how to fix it?