A - Content Too Large Editorial by en_translator
For beginners
This problem can be solved by checking if \(A _ 1+A _ 2+A _ 3+\cdots+A _ N\) is larger than \(M\).
One can compute \(A _ 1+A _ 2+A _ 3+\cdots+A _ N\) using a for statement, and compare it with \(M\) using an if statement.
The following is sample code.
#include <iostream>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
// Find the sum of sizes
int sum = 0;
for (int i = 0; i < N; ++i) {
int A;
cin >> A;
sum += A;
}
// Print Yes if the sum is M or less
if (sum <= M) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
N, M = map(int, input().split())
if sum(map(int, input().split())) <= M:
print('Yes')
else:
print('No')
posted:
last update: