SRM 480 DIV2 Easy(250) - Cryptography


Problem Statement

TopCoder Security Agency (TSA, established today) has just invented a new encryption system! This encryption system takes as its input a list of numbers to encrypt.

You work at TSA and your task is to implement a very important part of the encryption process. You are allowed to pick one number in the input list and increment its value by 1. This should be done in such way that the product of all numbers in the list after this change becomes as large as possible.

Given the list of numbers as int numbers, return the maximum product you can obtain. It is guaranteed that the return value will not exceed 262.


  • Class: Cryptography
  • Method: encrypt
  • Parameters: int
  • Returns: long
  • Method signature: long encrypt(int[] numbers) (be sure your method is public)


  • Time limit (s): 2.000
  • Memory limit (MB): 64


  • numbers will contain between 2 and 50 elements, inclusive.
  • Each element of numbers will be between 1 and 1000, inclusive.
  • The return value will not exceed 2^62.


import java.util.Arrays;

public class Cryptography {

    public long encrypt(int[] numbers) {
        numbers[0] += 1;
        long product = 1;
        for (int i = 0; i < numbers.length; i++) {
            product *= numbers[i];
        return product;