当前位置: 首页 > news >正文

AtCoder Weekday Contest 0035 Beta题解(AWC 0035 Beta A-E)

A - Warehouse Inventory Management

【题目来源】

AtCoder:A - Warehouse Inventory Management

【题目描述】

Takahashi works in the logistics department of a company. The company has \(N\) warehouses, numbered from warehouse \(1\) to warehouse \(N\). Each warehouse \(i\) \((1 \leq i \leq N)\) currently stores \(P_i\) items.
高桥在一家公司的物流部门工作。该公司有 \(N\) 个仓库,编号从 \(1\)\(N\)。每个仓库 \(i\)\(1 \leq i \leq N\))目前存储了 \(P_i\) 件货物。

Today, \(M\) shipping instructions to move items between warehouses have been issued. The \(j\)-th \((1 \leq j \leq M)\) shipping instruction is "move \(W_j\) items from warehouse \(U_j\) to warehouse \(V_j\)." Here, \(U_j \neq V_j\). There may be multiple shipping instructions between the same pair of warehouses.
今天,下达了 \(M\) 条在仓库间移动货物的指令。第 \(j\) 条(\(1 \leq j \leq M\))指令是"从仓库 \(U_j\) 移动 \(W_j\) 件货物到仓库 \(V_j\)"。这里,\(U_j \neq V_j\)。同一对仓库之间可能有多条移动指令。

The \(M\) shipping instructions are applied all at once, not sequentially. That is, the final number of items in each warehouse is obtained by taking the initial number of items, adding the total number of items coming into that warehouse, and subtracting the total number of items going out of that warehouse.
\(M\) 条指令是同时生效的,而不是顺序执行的。也就是说,每个仓库的最终货物数量是通过初始货物数量加上进入该仓库的货物总数,再减去从该仓库运出的货物总数得到的。

Takahashi wants to find the warehouse number with the most items after all shipping instructions have been applied. If there are multiple warehouses with the most items, find the one with the smallest warehouse number.
高桥希望找出在所有指令生效后,货物数量最多的仓库编号。如果有多个仓库的货物数量同为最多,则输出编号最小的仓库编号。

【输入】

\(N\) \(M\)
\(P_1\) \(P_2\) \(\ldots\) \(P_N\)
\(U_1\) \(V_1\) \(W_1\)
\(U_2\) \(V_2\) \(W_2\)
\(\vdots\)
\(U_M\) \(V_M\) \(W_M\)

  • The first line contains the number of warehouses \(N\) and the number of shipping instructions \(M\), separated by a space.
  • The second line contains the initial number of items in each warehouse \(P_1, P_2, \ldots, P_N\), separated by spaces.
  • The following \(M\) lines contain the details of each shipping instruction. If \(M = 0\), this part is not given.
  • The \(j\)-th line \((1 \leq j \leq M)\) contains the source warehouse number \(U_j\), the destination warehouse number \(V_j\), and the number of items to move \(W_j\) for the \(j\)-th shipping instruction, separated by spaces.

【输出】

Print on one line the warehouse number with the most items after all shipping instructions have been applied. If there are multiple warehouses with the most items, print the one with the smallest number.

【输入样例】

3 2
10 20 30
1 2 5
3 2 10

【输出样例】

2

【代码详解】

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200005;
int n, m, p[N];  // n: 人数, m: 交易次数, p: 每个人的净收入
struct Node
{int u, v, w;
} a[N];
signed main()
{cin >> n >> m;  // 输入人数和交易次数for (int i = 1; i <= n; i++)  // 输入初始金额{cin >> p[i];}for (int i = 1; i <= m; i++)  // 处理交易{int u, v, w;cin >> u >> v >> w;  // 从u给v转账wp[u] -= w;  // u减少wp[v] += w;  // v增加w}// 调试输出// for (int i=1; i<=n; i++)//     cout << p[i] << " ";// cout << endl;int maxn = -1, maxi = -1;  // 最大净收入和对应的人for (int i = 1; i <= n; i++)  // 查找最大净收入{if (p[i] > maxn){maxn = p[i];maxi = i;}}cout << maxi << endl;  // 输出净收入最大的人的编号return 0;
}

【运行结果】

3 2
10 20 30
1 2 5
3 2 10
2
http://www.jsqmd.com/news/572544/

相关文章:

  • 2026权威评测:TOP5毕业论文AIGC降重方案对比与首选建议
  • H3C堆叠
  • Qwen3-TTS-VoiceDesign惊艳效果:自然语言控声生成的中英日韩语音对比实录
  • Pixel Couplet Gen效果展示:支持中英双语横批+方言风格上联的创意案例
  • LabVIEW打造全能测控系统:从数据测量到变频器控制
  • MinIO启用HTTPS配置方法 - 麦克斯
  • Qwen3-14B开源模型实战:跨境电商多平台产品文案批量生成
  • 2026外贸B2B GEO服务商选型:AB客8大维度专业级测评报告 - 资讯焦点
  • 保姆级教程:Qwen3-TTS声音克隆快速部署,97ms低延迟实测
  • 突破90%抢票失败率:大麦自动抢票工具的5大核心方案
  • 终极指南:解决Mantine ScrollArea组件onBottomReached事件触发精度问题的实战技巧
  • TMP117高精度温度传感器Arduino驱动库详解
  • 探索ai协作:在快马平台对比claude code与其他ai模型的编程建议风格
  • 手把手教你用VSCode给Ai-WB2-12F烧录固件(含串口调试技巧)
  • 日语网课机构推荐|2026 靠谱线上日语学习平台测评 - 资讯焦点
  • 构建高效个人股票监控系统:TrafficMonitor插件解决方案
  • 万象熔炉 | Anything XL企业实操:营销部门批量生成社交平台配图工作流
  • 智慧卤味,一码追溯:万界星空MES方案
  • Linux - 网络编程Socket
  • Vue + G 实战:打造高校学生打卡数据可视化大屏
  • 终极指南:3分钟解决Windows苹果设备连接难题,免费驱动一键安装
  • C3D实战:从零构建视频行为识别模型
  • 2026年耐高温布行业十强厂商深度测评及排名 - 资讯焦点
  • 自学渗透测试第六天(Wireshark进阶与网络扫描)
  • 百度脑图正式下线,我让claw撸了个能私有部署的替代品
  • 2026年最全互联网大厂最全 Java 面试八股文题库
  • OpenCode + OpenSpec + Oh-My-OpenCode 联合 SDD/ATDD 开发指南
  • 关于Burp Suite抓不到本地的包的解决方法
  • 目录中不显示标题中间的软换行符Shift+Enter
  • 2026上海红木家具回收十大榜单:不压价、不玩套路、实在报价服务商排名 - 资讯焦点