forked from love1024/spoj-solution-with-explanation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLJIVE.cpp
39 lines (31 loc) · 838 Bytes
/
GLJIVE.cpp
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
#include<bits/stdc++.h>
using namespace std;
int main() {
//Take the input numbers
int arr[10];
for(int i=0;i<10;i++)
cin>>arr[i];
//Variables to store previous sum and current sum
int prev=0,sum=0;
//Loop over all variables
for(int i=0;i<10;i++) {
//Add current previous to current
prev = sum;
//Increase current sum
sum += arr[i];
//If sum is greater than 100
//Then check which is minimum
//Previous our current
if(sum >= 100) {
if(abs(100-prev) < abs(100-sum))
cout<<prev<<endl;
else
cout<<sum<<endl;
break;
}
//If it is last input and not greater
//Than 100 then print it
else if(i == 9)
cout<<sum<<endl;
}
}