Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 12:23:05
Task:Cent saving
Sender:Team Purkka
Submission time:2016-05-28 12:23:05
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main () {
  int t;
  cin>>t;
  for (int u = 0; u < t; u++) {
      int n;
      cin>>n;
      ll s = 0;
      ll fo = 0, th = 0;
      for (int i = 0; i < n; i++) {
	ll x;
	cin>>x;
	s += x;
	if (x % 5 < 3) s -= x % 5;
	else if (x % 5 == 3) th++;
	else fo++;
      }
      while (fo && th) {
	s -= 2;
	fo--;
	th--;
      }
      while (th >= 2) th -= 2, s -= 1;
      if (th) s += 2;
      while (fo >= 3) fo -= 3, s -= 2;
      if (fo) s += fo;
      cout<<s<<endl;
  }
}