Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <algorithm>
- # define N 100005
- using namespace std;
- ifstream fin(".in");
- ofstream fout(".out");
- /// metoda greedy = lacom
- /**
- var 1: calc min1, min2 si max1 max 2 si camparam cele 2 produse
- var 2: sortam vector cresc se compara prod primelor 2 valori si a ultimelor 2 valori
- */
- int n, a[N];
- ///var 2
- void Citire()
- {
- cin>>n;
- for(int i=1;i<=n;i++)
- cin>>a[i];
- }
- void Greedy()
- {
- sort(a+1, a+n+1);///STL
- cout<<max(a[1]*a[2], a[n]*a[n-1]);
- }
- int main()
- {
- Citire();
- Greedy();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement