CSES - HIIT Open 2016 - Results
Submission details
Task:Cent saving
Sender:Noname 01
Submission time:2016-05-28 12:32:22 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#20.06 sdetails

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;
  sav += c[1];
  sav += 2*c[2];
  sav -= 2*c[3];
  sav -= c[4];
  // 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;
  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;
}

Test details

Test 1

Verdict:

input
100
1000
528433894 255789530 559301042 ...

correct output
475191144965
460688647850
478543444030
475238936090
456736521510
...

user output
475191144945
460688647835
478543444010
475238936070
456736521500
...
Truncated

Test 2

Verdict:

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864928575