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 14:33:37
2016-05-28 14:25:11
2016-05-28 14:22:46
2016-05-28 14:19:18
2016-05-28 14:15:24
2016-05-28 14:06:41
2016-05-28 14:03:57
2016-05-28 13:59:57
2016-05-28 13:12:09
2016-05-28 12:52:39
Task:Cent saving
Sender:Oispa Kaljaa
Submission time:2016-05-28 14:33:37
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

#define i64 long long
using namespace std;

int main(){
  cin.sync_with_stdio(0);
  cin.tie(0);
  
  int tests; cin >> tests;
  i64 p[101010];
  while(tests--){
    int n; cin >> n;
    i64 sum = 0;
    for(int i = 0; i < n; i++){
      cin >> p[i];
      if(p[i]%5 < 3)
	sum+=p[i]-(p[i]%5);
      else
	sum+=p[i]+(5-p[i]%5);
    }
    i64 c[5] = {0};
    
    for(int i = 0; i < n; i++)
      c[p[i]%5]++;
    i64 be = 0;
    i64 m34 = min(c[3], c[4]);
    be = max(be, m34*5+(c[3]-m34)/2*5+(c[4]-m34)/3*5);
    i64 be2 = c[3]/2*5+c[4]/3*5;
    if(c[3]%2==1 && c[4]%3 > 0)
      be2+=5;
    be = max(be, be2);
    cout << sum-be << endl;
  }
    
    
  return 0;
}