백준 문제풀기/반복문

[Java] 백준 25304 영수증

psys 2022. 11. 14. 15:44
728x90

문제

https://www.acmicpc.net/problem/25304

 

25304번: 영수증

준원이는 저번 주에 살면서 처음으로 코스트코를 가 봤다. 정말 멋졌다. 그런데, 몇 개 담지도 않았는데 수상하게 높은 금액이 나오는 것이다! 준원이는 영수증을 보면서 정확하게 계산된 것

www.acmicpc.net

 

풀이

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int tot = Integer.parseInt(br.readLine());
		int n = Integer.parseInt(br.readLine());
		int sum = 0;
		
		for (int i = 0; i < n; i++) {
			String[] str = br.readLine().split(" ");
			sum+=Integer.parseInt(str[0])*Integer.parseInt(str[1]);
		}
		
		System.out.println(sum==tot?"Yes":"No");
	}
}