-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgreed.cpp
More file actions
57 lines (48 loc) · 776 Bytes
/
greed.cpp
File metadata and controls
57 lines (48 loc) · 776 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
#include<iostream>
#include<vector>
using namespace std;
long a[100001],b[100001],diff[100001];
int main(){
int n,max1,max2;
long max=-1,sum=0;
cin >> n;
for(int i=0; i<n; ++i)
cin>>a[i];
for(int i=0; i<n; ++i){
cin>>b[i];
diff[i] = b[i]-a[i];
}
//max=diff[0];
for(int i=0; i<n; ++i){
if(max<a[i]){
max1=i;
max=a[i];
}
if(max==a[i]){
if(diff[i]>diff[max1])
max1 = i;
}
}
max=-1;
for(int i=0; i<n; ++i){
if(max<a[i]){
max = a[i];
if(i != max1)
max2 = i;
}
if(max == a[i]){
if(diff[i] > diff[max2])
if(i != max1)
max2 = i;
}
}
cout<<max1 <<" " <<max2<<endl;
for(int i=0; i<n; ++i){
if(i!=max1 && i!=max2)
sum+=a[i];
}
if(sum<= diff[max1] + diff[max2])
cout<<"YES";
else
cout<<"NO";
}