|
|
back to boardWA #21 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; } |
|
|