CF991B Getting an A

本文解析了CodeForces平台上B题“GettinganA”的解决思路及代码实现。该题目聚焦于通过重做部分作业来提升成绩平均分至最优等级。文章首先介绍了题目背景和要求,随后提出了解决方案——通过将较低分数的作业重做为满分来最小化所需重做的作业数量。

原题链接:http://codeforces.com/contest/991/problem/B

Getting an A

Translator’s note: in Russia’s most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.

The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — 4.5 4.5 would be rounded up to 5 5 (as in example 3), but 4.4 would be rounded down to 4 4 .

This does not bode well for Vasya who didn’t think those lab works would influence anything, so he may receive a grade worse than 5 (maybe even the dreaded 2 2 ). However, the professor allowed him to redo some of his works of Vasya’s choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get 5 for the course. Of course, Vasya will get 5 5 for the lab works he chooses to redo.

Help Vasya — calculate the minimum amount of lab works Vasya has to redo.

Input

The first line contains a single integer n — the number of Vasya’s grades (1n100) ( 1 ≤ n ≤ 100 ) .

The second line contains n n integers from 2to5 — Vasya’s grades for his lab works.

Output

Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a 5 5 .

Examples
input

3
4 4 4

output

2

input

4
5 4 5 5

output

0

input

4
5 3 3 5

output

1

Note

In the first sample, it is enough to redo two lab works to make two 4s into 5 5 s.

In the second sample, Vasya’s average is already 4.75 so he doesn’t have to redo anything to get a 5 5 .

In the second sample Vasya has to redo one lab work to get rid of one of the 3s, that will make the average exactly 4.5 4.5 so the final grade would be 5 5 .

题解

排一遍序,从小到大填5

代码
#include<bits/stdc++.h>
using namespace std;
int a[105],sum,n;
void in(){scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",&a[i]),sum+=a[i];}
void ac()
{
    sort(a+1,a+1+n);
    for(int i=0;i<=n;++i,sum=sum-a[i]+5)
    if(sum>=4.5*n)printf("%d",i),exit(0);
}
int main(){in();ac();}
Collecting matplotlib Using cached matplotlib-3.10.3.tar.gz (34.8 MB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Installing backend dependencies: started Installing backend dependencies: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error Preparing metadata (pyproject.toml) did not run successfully. exit code: 1 [22 lines of output] + meson setup C:\Users\15306\AppData\Local\Temp\pip-install-1cm5zxfs\matplotlib_047401c8610d4b43a3cf47d3e24d7b9b C:\Users\15306\AppData\Local\Temp\pip-install-1cm5zxfs\matplotlib_047401c8610d4b43a3cf47d3e24d7b9b\.mesonpy-rudlakad -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\15306\AppData\Local\Temp\pip-install-1cm5zxfs\matplotlib_047401c8610d4b43a3cf47d3e24d7b9b\.mesonpy-rudlakad\meson-python-native-file.ini The Meson build system Version: 1.8.2 Source dir: C:\Users\15306\AppData\Local\Temp\pip-install-1cm5zxfs\matplotlib_047401c8610d4b43a3cf47d3e24d7b9b Build dir: C:\Users\15306\AppData\Local\Temp\pip-install-1cm5zxfs\matplotlib_047401c8610d4b43a3cf47d3e24d7b9b\.mesonpy-rudlakad Build type: native build Program python found: YES 3.12.0 3.12.0 Project name: matplotlib Project version: 3.10.3 ..\meson.build:1:0: ERROR: Unable to get gcc pre-processor defines: Compiler stdout: ----- Compiler stderr: cc: fatal error: cannot execute 'cc1': CreateProcess: No such file or directory compilation terminated. ----- A full log can be found at C:\Users\15306\AppData\Local\Temp\pip-install-1cm5zxfs\matplotlib_047401c8610d4b43a3cf47d3e24d7b9b\.mesonpy-rudlakad\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 25.0.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip error: metadata-generation-failed Encountered error while generating package metadata. See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
06-22
(.venv) C:\Users\13373\Desktop\PythonProject>pip install opencv-python Collecting opencv-python Using cached opencv_python-4.12.0.88-cp37-abi3-win_amd64.whl.metadata (19 kB) Collecting numpy<2.3.0,>=2 (from opencv-python) Using cached numpy-2.2.6.tar.gz (20.3 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [19 lines of output] + C:\Users\13373\Desktop\PythonProject\.venv\Scripts\python.exe C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12\vendored-meson\meson\meson.py setup C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12 C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12\.mesonpy-qvqylexd -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12\.mesonpy-qvqylexd\meson-python-native-file.ini The Meson build system Version: 1.5.2 Source dir: C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12 Build dir: C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12\.mesonpy-qvqylexd Build type: native build Project name: NumPy Project version: 2.2.6 Activating VS 18.0.2 C compiler for the host machine: cl (msvc 19.50.35719 "用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35719 版") C linker for the host machine: link link 14.50.35719.0 C++ compiler for the host machine: cl (msvc 19.50.35719 "用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.50.35719 版") C++ linker for the host machine: link link 14.50.35719.0 ..\meson.build:1:0: ERROR: Unknown compiler(s): [['cython'], ['cython3']] The following exception(s) were encountered: Running `cython3 -V` gave "[WinError 2] 系统找不到指定的文件。" A full log can be found at C:\Users\13373\AppData\Local\Temp\pip-install-6_8vdi1q\numpy_aa6d9609b67949b298b2b2744cf86f12\.mesonpy-qvqylexd\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. [notice] A new release of pip is available: 25.1.1 -> 25.3 [notice] To update, run: python.exe -m pip install --upgrade pip error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. 这是什么意思
最新发布
12-08
$ pip install pandas --only-binary=all -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting pandas Downloading https://pypi.tuna.tsinghua.edu.cn/packages/33/01/d40b85317f86cf08d853a4f495195c73815fdf205eef3993821720274518/pandas-2.3.3.tar.gz (4.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 12.3 MB/s 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [10 lines of output] + meson setup C:\Users\86188\AppData\Local\Temp\pip-install-uqm1ufie\pandas_7a53f778f2c3413f92cf1cb28b2a9344 C:\Users\86188\AppData\Local\Temp\pip-install-uqm1ufie\pandas_7a53f778f2c3413f92cf1cb28b2a9344\.mesonpy-ab6m2gu3 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=C:\Users\86188\AppData\Local\Temp\pip-install-uqm1ufie\pandas_7a53f778f2c3413f92cf1cb28b2a9344\.mesonpy-ab6m2gu3\meson-python-native-file.ini The Meson build system Version: 1.9.1 Source dir: C:\Users\86188\AppData\Local\Temp\pip-install-uqm1ufie\pandas_7a53f778f2c3413f92cf1cb28b2a9344 Build dir: C:\Users\86188\AppData\Local\Temp\pip-install-uqm1ufie\pandas_7a53f778f2c3413f92cf1cb28b2a9344\.mesonpy-ab6m2gu3 Build type: native build ..\meson.build:2:0: ERROR: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe A full log can be found at C:\Users\86188\AppData\Local\Temp\pip-install-uqm1ufie\pandas_7a53f778f2c3413f92cf1cb28b2a9344\.mesonpy-ab6m2gu3\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> pandas note: This is an issue with the package mentioned above, not pip. hint: See above for details. 86188@С□ε□□豸 MINGW64 ~/Desktop/wig绘制 $我去为什么阿
10-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值