1735B - Tea with Tangerines - CodeForces Solution


greedy math

Please click on ads to support us..

Python Code:

t = int(input()) for item in range(t):
    orange_count = int(input())
    orange_list = input().split()
    orange_sizes = []
    for element in range(len(orange_list)):
        orange_sizes.append(int(orange_list[element]))
    base_slice = min(orange_sizes)*2-1
    count=0
    for orange in orange_sizes:
        count+=(orange-1)//base_slice     print(count)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fixed(x) cout << fixed << setprecision(x)
#define endl '\n'
void solved()
{
    ll n, c = 0;
    cin >> n;
    ll ar[n], y = 1e9;
    for (int i = 0; i < n; i++)
    {
        cin >> ar[i];
        y = min(y, ar[i]);
    }
    y = y * 2 - 1;
    for (int i = 0; i < n; i++)
    {
        if (ar[i] > y)
        {
            c = c + ar[i] / y;
            if (ar[i] % y == 0)
                c--;
        }
    }
    cout << c << endl; // 19 9
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while (t--)
        solved();
    return 0;
}


Comments

Submit
0 Comments
More Questions

544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement
903A - Hungry Student Problem
52B - Right Triangles
1712A - Wonderful Permutation
1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations