Codeforces #38 A "Army"
問題:http://codeforces.com/contest/38/problem/A
本番.
全部でn階級あって,上の階級にあがるときに必要な年数が与えられる.
ある階級からある階級へ上がるために必要な総年数を求める.
import java.util.*; public class A_Army { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] a = new int[n]; for (int i = 1; i < n; ++i) { a[i] = s.nextInt(); } int sum = 0; for(int i = s.nextInt(),e = s.nextInt(); i < e; ++i){ sum += a[i]; } System.out.println(sum); } }