nitskp's blog

By nitskp, history, 7 years ago, In English

Hi,

Today I submitted my solution to 455-A Boredom (http://codeforces.com/problemset/problem/455/A), and it seemed to be working fine on my home PC, but when I tested it on Codeforces judge it gave wrong answer as soon as on test two. I am running Linux Ubuntu if that may be helpful. Here is the code:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;



int main(int argc, char const *argv[])
{
	
	int n;
	cin>>n;
	vector<int > a, dp;



	for (int i = 0; i < n; ++i){
		int temp;
		cin>>temp;
		a.push_back(temp);
	}
	dp.clear();
	dp.resize(n + 1);
	sort(a.begin(),a.end());

	int count = 1;

	vector<pair<int,int > > v;

	for (int i = 0; i < n - 1; ++i){
		if(a[i] != a[i + 1]){
			pair<int, int > temp;
			temp.first = a[i];
			temp.second = count;
			v.push_back(temp);
			count = 1;
		}
		else{
			count++;
		}
	}

	pair<int, int > temp;
			temp.first = a[n - 1];
			temp.second = count;
			v.push_back(temp);
			dp[0] = 0;
	dp[1] = v[n - 1].first * v[n - 1].second;
	for(int i = 2; i <= n; i++){
		dp[i] = max(dp[i  - 1], dp[i - 2] + v[n - i].first * v[n - i].second);

	}
	int ans = dp[n];

	cout<<ans;

	return 0;
}

455A - Boredom

It is giving garbage value in the codeforces judge. Can anyone tell me whats the problem is?

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it