-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMurder.cpp
More file actions
76 lines (38 loc) · 980 Bytes
/
Murder.cpp
File metadata and controls
76 lines (38 loc) · 980 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Once detective Saikat was solving a murder case.
While going to the crime scene he took the stairs and saw that a number is written on every stair.
He found it suspicious and decides to remember all the numbers that he has seen till now.
While remembering the numbers he found that he can find some pattern in those numbers.
So he decides that for each number on the stairs
he will note down the sum of all the numbers previously seen on the stairs which are smaller than the present number.
Calculate the sum of all the numbers written on his notes diary.
input:
5
1 5 3 6 4
output:
15
*/
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n;
cin>>n; long long sum=0;
vector<long long> a(n);
for(int i=0;i<n;i++)
{ cin>>a[i]; }
for(int i=0;i<n;i++)
{
for(int j=i;j>=0;j--)
{
if(a[i]>a[j])
{ sum=sum+a[j]; }
}
}
cout<<sum;
}
}