现给定n个整数,并定义一个非负整数m,且令f(m) = (m%a1)+(m%a2)+...+(m%an)。
此处的X % Y的结果为X除以Y的余数。
现请你找出一个m,求出f(m)的最大值。
输入包含两行,第一行为一正整数n,(1<n<=3000)
第二行为n个整数a1,a2,...,an ,其中(2<=ai<=10^5)
输出仅包含一行,输出f(m)的最大值
3 3 4 6
10
就样例而言,当m取11时可取得最大值。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int result = 0; for (int i = 0; i < n; i++) { result += in.nextInt(); result--; } System.out.println(result); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * @Author: coderjjp * @Date: 2020-05-09 17:54 * @Description: * @version: 1.0 */ public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.valueOf(br.readLine()); int ans = 0; String[] line2 = br.readLine().split(" "); for (int i = 0; i < n; i++) ans += Integer.valueOf(line2[i]); System.out.println(ans - n); } }
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] a = new int[n]; int sum = 0; for (int i=0;i<n;i++) { a[i] = input.nextInt(); sum = sum + a[i]; } System.out.println(sum-n); } }