codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1176B.md (1762B)


      1 Source: https://codeforces.com/problemset/problem/1176/B
      2 
      3 B. Merge it!
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots , a_n$.
     22 
     23 In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $[2, 1, 4]$ you can obtain the following arrays: $[3, 4]$, $[1, 6]$ and $[2, 5]$.
     24 
     25 Your task is to find the maximum possible number of elements divisible by $3$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.
     26 
     27 You have to answer $t$ independent queries.
     28 
     29 Input
     30 
     31 The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of queries.
     32 
     33 The first line of each query contains one integer $n$ ($1 \le n \le 100$).
     34 
     35 The second line of each query contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$).
     36 
     37 Output
     38 
     39 For each query print one integer in a single line — the maximum possible number of elements divisible by $3$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 2
     47 5
     48 3 1 2 3 1
     49 7
     50 1 1 1 1 1 2 2
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 3
     57 3
     58 ```
     59 
     60 Note
     61 
     62 In the first query of the example you can apply the following sequence of operations to obtain $3$ elements divisible by $3$: $[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$.
     63 
     64 In the second query you can obtain $3$ elements divisible by $3$ with the following sequence of operations: $[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$.