hello, I'm trying to solve this problem http://codeforces.com/problemset/problem/762/B.
and I'm getting a runtime error -1073741819, although the code gives me the correct output locally.
my submission is http://codeforces.com/contest/762/submission/24280499
my code is
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main( int argc, char **argv )
{
ios::sync_with_stdio( 0 );
int a, b, c;
std::cin >> a >> b >> c;
int m;
cin >> m;
std::set<int> ps;
std::set<int> us;
std::string t;
int p;
for ( int i = 0; i < m; i++ ) {
cin >> p;
cin >> t;
if ( t[0] == 'U' ) {
us.insert( p );
} else {
ps.insert( p );
}
}
int num = 0;
int tprice = 0;
for ( set<int>::iterator i = us.begin(); i != us.end(); i++ ) {
if ( a > 0 ) {
num++;
tprice += *i;
us.erase( i );
a--;
} else {
break;
}
}
for ( set<int>::iterator i = ps.begin(); i != ps.end(); i++ ) {
if ( b > 0 ) {
num++;
tprice += *i;
ps.erase( i );
b--;
} else {
break;
}
}
us.insert( ps.begin(), ps.end() );
for ( set<int>::iterator i = us.begin(); i != us.end(); i++ ) {
if ( c > 0 ) {
num++;
tprice += *i;
c--;
} else {
break;
}
}
cout << num << " " << tprice << "\n";
return 0;
}
Locally, I'm using this compile command
g++ -O2 main.cpp -lm -o main
Any help would be appreciated.