-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisitfibonacci.cpp
More file actions
52 lines (41 loc) · 960 Bytes
/
isitfibonacci.cpp
File metadata and controls
52 lines (41 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//{ Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
class Solution {
public:
long long solve(int n, int k, vector<long long> GeekNum) {
// code here
if(n==k){
return GeekNum[n-1];
}
long long sum=0;
for(int i=0;i<k;i++){
sum+=GeekNum[i];
}
vector<long long>v=GeekNum;
v.push_back(sum);
for(int i=k+1;i<n;i++){
sum=sum+v[i-1]-v[i-k-1];
v.push_back(sum);
}
return v[n-1];
}
};
//{ Driver Code Starts.
int main() {
int T;
cin >> T;
while (T--) {
int N, K;
cin >> N >> K;
vector<long long> GeekNum(K);
for (int i = 0; i < K; i++) cin >> GeekNum[i];
Solution ob;
cout << ob.solve(N, K, GeekNum) << "\n";
}
return 0;
}
// } Driver Code Ends