Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main(){
int n; scanf("%d",&n);
int *years = new int[n + 1];
years[0] = years[1] = 0;
int temp(0), currentRank(0), futureRank(0);
for(int k = 2; k <= n; k++){scanf("%d", &temp); years[k] = years[k - 1] + temp;}
scanf("%d %d", ¤tRank, &futureRank);
printf("%d", years[futureRank] - years[currentRank]);
return 0;
}
Copy The Code &
Try With Live Editor
Input
3
5 6
1 2
5 6
1 2
Output
5
Demonstration
Codeforces Solution-A. Army-Solution in C, C++, Java, Python