time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n,
where 1 is the lowest rank and n is the highest rank.

One needs exactly di years
to rise from rank i to rank i + 1. Reaching a certain
rank i having not reached all the previous i - 1 ranks
is impossible.

Vasya has just reached a new rank of a, but he dreams of holding the rank of b.
Find for how many more years Vasya should serve in the army until he can finally realize his dream.

Input

The first input line contains an integer n (2 ≤ n ≤ 100).
The second line contains n - 1 integers di (1 ≤ di ≤ 100).
The third input line contains two integers a and b (1 ≤ a < b ≤ n).
The numbers on the lines are space-separated.

Output

Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.

Sample test(s)
input
3
5 6
1 2
output
5
input
3
5 6
1 3
output
11

解题思路:就是简单的求区间和。

直接开个和数组,a[i]代表i之前(包含i)的全部数的和。

查询时。直接两个和减一下就可以。

AC代码:

#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int c[105]; int main()
{
#ifdef sxk
freopen("in.txt","r",stdin);
#endif
int n, a, b, t;
while(scanf("%d",&n)!=EOF)
{
c[0] = 0;
scanf("%d", &c[1]);
for(int i=2; i<=n-1; i++){
scanf("%d", &t);
c[i] = c[i-1] + t;
}
scanf("%d%d", &a, &b);
printf("%d\n", c[b-1] - c[a-1]);
}
return 0;
}

School Personal Contest #1 (Codeforces Beta Round #38)---A. Army的更多相关文章

  1. D. Frets On Fire 【二分,前缀和】 (Codeforces Global Round 2)

    题目传送门:http://codeforces.com/contest/1119/problem/D D. Frets On Fire time limit per test 1.5 seconds ...

  2. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)

    A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  4. Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)

    Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...

  5. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  6. Codeforces Beta Round #69 (Div. 2 Only)

    Codeforces Beta Round #69 (Div. 2 Only) http://codeforces.com/contest/80 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #40 (Div. 2)

    Codeforces Beta Round #40 (Div. 2) http://codeforces.com/contest/41 A #include<bits/stdc++.h> ...

  8. Codeforces Beta Round #14 (Div. 2)

    Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/s ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. 对比hive和mysql查询汇总

    由于底层的处理机制大不相同,hive和mysql在查询上还是有较大差异的! 单个表的select操作 最简单的查询 ,字段2 frome 表名 where 字段 [not]in(元素1,元素2): 例 ...

  2. POJ_1018_(dp)

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28273   Accepted:  ...

  3. 安装svn

    一.安装 1.查看是否安装cvs rpm -qa | grep subversion 2.安装 yum install subversion 3.测试是否安装成功 /usr/bin/svnserve ...

  4. 微服务网关从零搭建——(六)ocelot配置追踪功能

    butterfly 准备工作 首先下载buterfly release版本 解压并通过命令启动:dotnet Butterfly.Web.dll --EnableHttpCollector=true ...

  5. 模板—treap

    #include<iostream> #include<cstdio> #include<cstdlib> #define INF 0x7fffffff using ...

  6. eclipse 中常用快捷键

    * 字母大小写转换 ctrl+shift+x   转为大写 ctrl+shift+y   转为小写 * eclipse 自动生成对象来接收方法的返回值的快捷键 说明:光标一定要定位到要自动生成返回值对 ...

  7. Java第九周总结

  8. Django DTL模板语法中的循环

    from django.shortcuts import render def index(request): context={ 'books':[ '5年高考3年模拟', '家猪养殖与配种', ' ...

  9. 51NOD 1287 加农炮(不水的线段树)

    >>点击进入原题测试<< Input示例 Output示例 思路:刚开始以为结点存最大值就行了,然后大于左子树的最大值就能进入右子树:然后发现样例都过不了:后面发现,并不是这个 ...

  10. Unity对象的所有组件深拷贝与粘贴

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/51454847 作者:car ...