Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- long c,a[10005],p,i,j,ln,t,tm,mx,f,k,ai,aj,p1,p2;
- while( scanf("%ld\n",&c) != EOF)
- {
- i=0;
- for(k=0; k<c; k++)
- {
- scanf("%ld",&a[i]);
- i++;
- }
- scanf("%ld",&p);
- ln = i;
- mx = 0;
- f = 0;
- p1 = 0;
- p2 = 0;
- for(i=0; i<ln; i++)
- {
- t = p - a[i];
- for(j=i+1; j<ln; j++)
- {
- if( a[j] == t)
- {
- ai = a[i];
- aj = a[j];
- if( ai >= aj)
- {
- tm = ai;
- ai = aj;
- aj = tm;
- }
- if( f == 1)
- {
- if( mx <= (aj - ai))
- {
- mx = aj - ai;
- continue;
- }
- }
- p1 = ai;
- p2 = aj;
- mx = aj - ai;
- f=1;
- }
- }
- }
- printf("Peter should buy books whose prices are %ld and %ld.\n\n",p1,p2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement