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. Angular——依赖注入

    基本介绍 1.AngularJS采用模块化的方式组织代码,将一些通用逻辑封装成一个对象或函数,实现最大程度的复用,这导致了使用者和被使用者之间存在依赖关系. 2.所谓依赖注入是指在运行时自动查找依赖关 ...

  2. Farseer.net轻量级开源框架 入门篇:分类逻辑层

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 缓存逻辑层 下一篇:Farseer.net轻量级开源框架 入门篇: 添加数据详解 ...

  3. HDU_1018_n(1e7)的阶乘的结果的位数

    http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others)     ...

  4. Python游戏开发:pygame游戏开发常用数据结构

    一.数组与列表 数组可以理解为简化的列表.像我们之前使用的pygame.sprite.Group这样的精灵组,也是一个列表.列表的元素是可变的,它具有添加.删除.搜索.排序等多种方法. 1.一维列表 ...

  5. Vue指令6:v-show

    根据表达式的真假值来渲染元素 用法大致一样: <h1 v-show="ok">Hello!</h1> 不同的是带有 v-show 的元素始终会被渲染并保留在 ...

  6. A4. JVM 内存分配及回收策略

    [概述] Java 技术体系中所提倡的自动内存管理最终可以归结为自动化地解决两个问题:给对象分配内存以及回收分配给对象的内存. 对象的内存分配,往大方向讲,就是在堆上分配,对象主要分配在新生代的 Ed ...

  7. 网络编程 - join及守护线程

    一.Join实例(join理解为等待)import threading,timedef run(n): time.sleep(3) print ("task",n)start = ...

  8. 数据类型对应字节数(32位,64位 int 占字节数)

    数据类型对应字节数(32位,64位 int 占字节数) 可用如sizeof(char),sizeof(char*)等得出 32位编译器: char :1个字节 char*(即指针变量): 4个字节(3 ...

  9. php第二十五节课

    详情删除 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  10. idea14远程调试linux下的tomcat

    进入到idea的tomcat的run/debug配置,新建个remote tomcat,然后填写相关信息,如上图(注意远程调试端口). 再选择Startup/Connection,如下图所示: 到此, ...