991B - Getting an A - CodeForces Solution


greedy sortings *900

Please click on ads to support us..

Python Code:

n = int(input())
sum = 0

ls = list(map(int, input().split()))

for i in range(0,n):
    sum += ls[i]
ls.sort()
avg = sum/n
ans = 0

if(avg >= 4.5):
    print(0)
else:
    for i in range(0,n):
        if(avg >= 4.5):
            break
        else:
            sum += (5- ls[i])
            ls[i] = 5
            avg = sum/n
            ans+=1

    print(ans)

    
    

C++ Code:

#include <iostream>
#include "vector"
#include "cmath"
#include "iomanip"
#include "string"
#include "list"
#include "algorithm"
#include "set"

#include "map"
#include "numeric"
using namespace  std;
long long mod = 1e9 + 7;
#define ll long long
#define ld long double
#define s set<int>
#define pair pair<int,int>
const int  SIZE = 1e6+1;
const ld e = 1e-12;
int convert(long long n) {
    int dec = 0, i = 0, rem;

    while (n!=0) {
        rem = n % 10;
        n /= 10;
        dec += rem * pow(2, i);
        ++i;
    }

    return dec;
}
ll gcd(ll a, ll b)
{
    if (a * b == 0) return a + b;
    if (a < b)
        return gcd(a,b%a);
    else
        return gcd(a%b,b);

}
void fastio()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
}
ll fact(ll a)
{
    ll sum = 1;
    for (int i = 2; i <= a; i++)
    {
        sum *= i;
    }
    return sum;

}

int qpow(int a,int b) {
    int r = 1;
    while (b) {
        if (b & 1)r = r % mod * a % mod;
        a = a % mod * a % mod;
        b >>= 1;
    }
    return r;
}


bool comp(pair a, pair b)
{
    return (a.first < b.first);
}

int main() {
    fastio();
    int n;
    cin >> n;
    vector<ld>a(n);
    ld sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int count = 0;
    sort(a.begin(),a.end());
    for (int i = 0; i < n; i++) {
        if (sum / n >= 4.5) {
            break;
        }
        if (a[i] != 5.0) {
            sum += fabs(a[i] - 5.0);
            count++;
        }
       // cout << sum / n << '\n';
    }
    cout << count << " ";
}




















Comments

Submit
0 Comments
More Questions

1714E - Add Modulo 10
1714A - Everyone Loves to Sleep
764A - Taymyr is calling you
1714B - Remove Prefix
1264F - Beautiful Fibonacci Problem
52A - 123-sequence
1543A - Exciting Bets
1714D - Color with Occurrences
215B - Olympic Medal
1445A - Array Rearrangment
1351A - A+B (Trial Problem)
935B - Fafa and the Gates
1291A - Even But Not Even
1269A - Equation
441A - Valera and Antique Items
1702C - Train and Queries
816B - Karen and Coffee
838D - Airplane Arrangements
148B - Escape
847G - University Classes
1110A - Parity
1215B - The Number of Products
604C - Alternative Thinking
1204C - Anna Svyatoslav and Maps
322A - Ciel and Dancing
1689B - Mystic Permutation
1711B - Party
1702D - Not a Cheap String
1714F - Build a Tree and That Is It
1703F - Yet Another Problem About Pairs Satisfying an Inequality