atcoder ABC 356-B题详解
Problem Statement
Takahashi is health-conscious and concerned about whether he is getting enough of M types of nutrients from his diet.
For the i-th nutrient, his goal is to take at least Ai units per day.
Today, he ate N foods, and from the i-th food, he took Xi,j units of nutrient j.
Determine whether he has met the goal for all M types of nutrients.
Constraints
1≤N≤100
1≤M≤100
0≤Ai,Xi,j≤107
All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
A1 … AM
X1,1 … X1,M
⋮
XN,1 … XN,M
Output
Print Yes if the goal is met for all M types of nutrients, and No otherwise.
Sample Input 1
2 3
10 20 30
20 0 10
0 100 100
Sample Output 1
Yes
For nutrient 1, Takahashi took 20 units from the 1-st food and 0 units from the 2-nd food, totaling 20 units, thus meeting the goal of taking at least 10 units.
Similarly, he meets the goal for nutrients 2 and 3.
Sample Input 2
2 4
10 20 30 40
20 0 10 30
0 100 100 0
Sample Output 2
No
The goal is not met for nutrient 4.
思路分析:
本题需要比较每天摄入的总量和目标值的比较,可以定义一个数组来存储每天摄入的总量来对目标值进行比较,定义一个ans来计数,表示摄入量达标了几天。
code:
#include <iostream>
using namespace std;
int n,m,x1;
const int N=110;
long long a[N];
long long x[N][N];
long long b[N];
int ans=0;
int main(int argc, const char * argv[]) {
cin>>n>>m;
for(int i=1;i<=m;i++) cin>>a[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) cin>>x[i][j];
for(int j=1;j<=m;j++)
for(int i=1;i<=n;i++) b[j]=b[j]+x[i][j];
for(int i=1;i<=m;i++){
if(b[i]>=a[i]){
ans++;
}
}
if(ans==m) cout<<"Yes";
else cout<<"No";
return 0;
}
标签:atcoder,ABC,20,goal,int,long,356,units,100
From: https://blog.csdn.net/2301_80662593/article/details/139440239