ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1917. Titan Ruins: Deadly Accuracy

WA #21
Posted by bladeandsoul 11 Jul 2013 12:53
what is it? plz
// Deadly Accuracy.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <algorithm>
using namespace std;
int n=0,p=0;
int counter[1000001]={0};

int main()
{
cin>>n>>p;
int a=0;
int maxCoins=0;
int timeOfAttack=0;

for (int i=0;i<n;i++){
cin>>a;
counter[a]++;
}

int tempR=0;
int tempCoin=0;
for (int i=1;i<=p && i<=1000000;i++)
{
if (i*counter[i]<=p && counter[i]!=0)
{

if (i*(tempCoin+counter[i])>p)
{
if (tempR<=p && tempCoin!=0 &&tempR !=0){
timeOfAttack++;
maxCoins+=tempCoin;
}
tempCoin=counter[i];

}
else
tempCoin+=counter[i];
tempR=i*tempCoin;

}
}
if (tempR<=p && tempCoin!=0 &&tempR !=0)
{
timeOfAttack++;
maxCoins+=tempCoin;
}

cout<<maxCoins<<' '<<timeOfAttack<<endl;
cin>>a;
return 0;
}