CF#808 C. Tea Party(贪心)

本文介绍了一个有趣的算法问题:如何在确保公平的前提下将有限的茶水合理分配到不同容量的茶杯中。问题需要考虑茶杯的容量、茶水总量及公平分配原则。
C. Tea Party
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumesa1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that:

  • Every cup will contain tea for at least half of its volume
  • Every cup will contain integer number of milliliters of tea
  • All the tea from the teapot will be poured into cups
  • All friends will be satisfied.

Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj.

For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.

Input

The first line contains two integer numbers n and w (1 ≤ n ≤ 100).

The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.

If it's impossible to pour all the tea and satisfy all conditions then output -1.

Examples
input
2 10
8 7
output
6 4 
input
4 4
1 1 1 1
output
1 1 1 1 
input
3 10
9 8 10
output
-1
Note

In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.

题意:有 n 个茶杯,茶壶里有 m 毫升茶,每个茶杯大小不等,我们要满足以下三个条件 :1. 每个茶杯中的茶要超过茶杯容量的一半 2. 每个茶杯中倒的茶必须是整数毫升 3. 大茶杯中的茶的容量不能少于任意一个小茶杯中的茶的容量,若 n ,m 不满足条件,输出 -1 ,否则输出一种满足条件的情况


#include<bits/stdc++.h>
using namespace std;

const int N = 100 + 10;
int n, w;
struct xx{
    int num, pos;
    int ans;
} a[N];

bool cmp1(xx a, xx b){
    return a.num > b.num;
}

bool cmp2(xx a, xx b){
    return a.pos < b.pos;
}

int main()
{
    while(scanf("%d%d", &n, &w) == 2){
        int ww = w;
        int Maxsum = 0, Minsum = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d", &a[i].num);
            a[i].pos = i;
            a[i].ans = a[i].num/2;
            if(a[i].num&1) a[i].ans++;
            Maxsum += a[i].num;
            Minsum += a[i].ans;
            w -= a[i].ans;
        }
        if(ww > Maxsum || ww < Minsum){
            printf("-1\n");
        }
        else
        {
            sort(a+1, a+1+n, cmp1);
            for(int i = 1; i <= n; i++){
                if(w + a[i].ans >= a[i].num){
                    w -= a[i].num-a[i].ans;
                    a[i].ans = a[i].num;
                }
                else{
                    a[i].ans += w;
                    w = 0;
                }

                if(!w) break;
            }
            sort(a+1, a+1+n, cmp2);
            for(int i = 1; i <= n; i++){
                printf("%d%c", a[i].ans, i<n? ' ':'\n');
            }
        }
    }
}

<think> 我们正在解决MCP-Kali-Server项目部署中的资源国内源替换问题。用户希望将克隆项目、创建虚拟环境、安装依赖库、配置和启动服务端等步骤中涉及的资源替换为国内源,以加速部署过程。 解决方案: 1. 项目克隆:使用国内镜像源(如GitHub镜像站) 2. Python虚拟环境:使用国内源下载Python(如果需要)或使用系统自带Python 3. 依赖库安装:使用国内PyPI镜像(如清华、阿里云) 4. 服务端配置和启动:不涉及外部资源,无需替换 具体步骤: 一、项目克隆替换为国内源 由于GitHub克隆可能较慢,我们可以使用镜像站。常见镜像站有: - https://hub.njuu.cf - https://hub.yzuu.cf - https://ghproxy.com 将原始URL:https://github.com/Wh0am123/MCP-Kali-Server.git 替换为镜像URL(以hub.njuu.cf为例): https://hub.njuu.cf/Wh0am123/MCP-Kali-Server.git 命令示例: ```bash git clone https://hub.njuu.cf/Wh0am123/MCP-Kali-Server.git ``` 二、创建Python虚拟环境 这一步通常不需要外部资源,但若要下载特定Python版本,可使用国内源(如华为镜像)下载Python安装包。不过,Kali Linux通常自带Python,因此我们主要关注pip源的替换。 三、依赖库安装替换为国内源 在安装依赖库时,使用国内PyPI镜像可以极大加快速度。常用镜像: - 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple - 阿里云:https://mirrors.aliyun.com/pypi/simple - 豆瓣:https://pypi.douban.com/simple 有两种方式指定镜像源: a) 临时使用(在pip install命令后添加-i参数) b) 永久修改(创建或修改pip配置文件) 在本项目中,我们使用临时方式,因为项目可能只需要一次性安装依赖。 修改后的安装命令: ```bash pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 如果没有requirements.txt,则手动安装依赖: ```bash pip install flask requests impacket bloodhound coercer -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 四、配置服务端和启动服务端 这两步不涉及从外部下载资源,因此不需要替换源。 完整修正后的部署流程: 1. 克隆项目(使用镜像源): ```bash git clone https://hub.njuu.cf/Wh0am123/MCP-Kali-Server.git cd MCP-Kali-Server ``` 2. 创建Python虚拟环境: ```bash python3 -m venv venv source venv/bin/activate ``` 3. 安装依赖库(使用清华源): ```bash pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 如果requirements.txt不存在: ```bash pip install flask requests impacket bloodhound coercer -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 4. 配置服务端: ```bash cp config.example.py config.py # 编辑config.py(可选) ``` 5. 启动服务端: ```bash python3 kali_server.py ``` 注意:如果使用国内镜像源后遇到SSL证书问题,可以在pip命令中添加`--trusted-host`参数: ```bash pip install ... -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn ``` 生成相关问题: §§相关问题§§ 1. 如何永久修改pip的源为国内镜像? 2. 除了GitHub镜像站,还有哪些方法可以加速GitHub项目的克隆? 3. 在Kali Linux中如何安装特定版本的Python? 4. 如何解决pip安装依赖时的SSL证书验证错误? </think> 以下是MCP-Kali-Server项目部署过程中关键资源的国内镜像源解决方案,针对克隆、环境创建、依赖安装等环节进行了优化: --- ### 一、项目克隆国内源 **问题**:`git clone`连接被重置 **解决方案**: ```bash # 使用GitHub镜像站(推荐) git clone https://hub.yzuu.cf/Wh0am123/MCP-Kali-Server.git # 备用镜像(选择延迟最低的) git clone https://gitclone.com/github.com/Wh0am123/MCP-Kali-Server.git ``` > **说明**:国内镜像站通过缓存GitHub内容实现加速,速度可提升3-10倍[^1] --- ### 二、Python虚拟环境配置 **依赖**:Python解释器 **国内源配置**: ```bash # 更新APT源为阿里云镜像 sudo sed -i 's|http://http.kali.org|https://mirrors.aliyun.com/kali|g' /etc/apt/sources.list # 安装Python环境 sudo apt update && sudo apt install -y python3.11 python3.11-venv # 创建虚拟环境(使用系统自带Python) python3.11 -m venv venv ``` --- ### 三、依赖库安装国内源 **核心依赖**:`flask`, `requests`, `impacket`等 **PyPI镜像配置**: ```bash # 永久配置清华源 echo "[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn" > ~/.pip/pip.conf # 安装依赖(自动使用镜像源) source venv/bin/activate pip install -r requirements.txt # 若无文件则手动安装: pip install flask impacket bloodhound coercer ``` > **可选镜像站**: > - 阿里云:`https://mirrors.aliyun.com/pypi/simple` > - 豆瓣:`https://pypi.douban.com/simple` > - 华为云:`https://repo.huaweicloud.com/repository/pypi/simple` --- ### 四、服务端配置优化 **缺失文件处理**: ```bash # 若缺少config.example.py,从GitHub直接下载 curl -O https://raw.githubusercontent.com/Wh0am123/MCP-Kali-Server/main/config.example.py # 创建配置文件 cp config.example.py config.py sed -i 's/5000/8080/g' config.py # 修改默认端口 ``` --- ### 五、服务启动命令 **修复文件路径错误**: ```bash # 确认入口文件位置(通常为app.py或main.py) find . -name "*.py" | grep -E 'app|main|server' # 启动服务(示例) python3 src/kali_server.py # 根据实际路径调整 ``` --- ### 六、完整优化流程 ```mermaid graph LR A[克隆项目] --> B[hub.yzuu.cf镜像] B --> C[配置阿里云APT源] C --> D[创建Python虚拟环境] D --> E[设置清华PyPI源] E --> F[安装依赖] F --> G[修改配置文件] G --> H[启动服务] ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值