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:38:26
2016-05-28 12:32:22
2016-05-28 12:29:13
Task:Cent saving
Sender:Noname 01
Submission time:2016-05-28 12:38:26
Status:READY
Result:ACCEPTED

Show test data

Code

// NONAME-01

#include <bits/stdc++.h>


using namespace std;


vector<long long> a;
long long c[5];
long long total;
int n;

void Load()
{
  cin >> n;
  a.resize(n);
  total = 0;
  memset(c, 0, sizeof(c));
  for (int i = 0; i < n; i++) {
	  cin >> a[i];
	  total += a[i];
	  c[a[i] % 5]++;
  }
}

void Solve()
{
  long long sav = 0;
  // c0 ignore;
  // c1 -> save 1;
  // c2 -> save 2;
  //cerr << "total = " << total << "\n";
  sav += c[1];
  sav += 2*c[2];
  sav -= 2*c[3];
  sav -= c[4];
  //cerr << "sav = " << sav << "\n";  
  // group c[4] and c[3] for +5;
  long long i = c[4];
  if (i > c[3]) i = c[3];
  sav += 5*i;
  c[4] -= i;
  c[3] -= i;
  // group c3 together;
  i = c[3] / 2;
  sav += 5*i;  
  // group c4 together;
  i = c[4] / 3;
  sav += 5*i;
  //cerr << "sav = " << sav << "\n";
  cout << total - sav << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int nt, tt;
  cin >> nt;
  for (tt = 0; tt < nt; tt++) {
  Load();
  Solve();
  }
  return 0;
}