Why is this problem under Greedy?

Codeforces Problem

My Solution:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int game = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if (isOnesMoreThanTwo(a,b,c)) {
                game++;
            }
        }
        System.out.println(game);
    }

    public static boolean isOnesMoreThanTwo(int a, int b, int c) {

        int numberOfOnes = 0;
        if(a==1){
            numberOfOnes++;
        }
        if(b==1){
            numberOfOnes++;
        }
        if(c==1){
            numberOfOnes++;
        }

        if (numberOfOnes >= 2)
            return true;
        else
            return false;
    }
}

I am getting a Run time error. I cant understand why?

'Cause this is just simple greedy :

Input n
Repeat n times:
      input a, b, c
      if a+b+c>=2 ans++
Print ans
1 Like

I edited your code a lil bit and it got accepted

Blockquote
import java.util.Scanner;

public class Solution {

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int game = 0;
    for (int i = 0; i < n; i++) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a+b+c>=2) {
            game++;
        }
    }
    System.out.println(game);
    sc.close();
}    

}