-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfebimpr.cpp
71 lines (54 loc) · 995 Bytes
/
febimpr.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
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
68
69
70
71
#include<iostream>
using namespace std;
static int isValidTriangle(int a, int b, int c);
int main()
{
long long int n,r,l,count=0;
int f=1;
cin>>n>>r>>l;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int x=((n-1)*n)/2;
int b[x];
int w;
int c[l-r+1];
int y=r;
int i=0;
for(int j=0;j<n;j++){
for(int k=j+1;k<n;k++){
b[i]=a[j]*10+a[k];
i++;
}}
for(int n=0;n<l-r+1;n++){
c[n]=y;
y++;
}
for(int k=0;k<x;k++){
int s1=b[k]%10;
int s2=b[k]/10;
for(int m=0;m<l-r+1;m++){
if(c[m]!=0)
w= isValidTriangle(s1,s2,c[m]);
if(w==1){
c[m]=0;
}
}
}
for(int m=0;m<l-r+1;m++){
if(c[m]==0)
count++;
}
cout<<count<<endl;
}
static int isValidTriangle(int a, int b, int c){
int longestSide = a;
if (b > longestSide )
longestSide = b;
if(c > longestSide )
longestSide = c;
if( (longestSide >= (a + b+c -longestSide)) || (a == 0 )|| ( b == 0) || (c == 0))
return 0;
else return 1;
}