Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <utility>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <math.h>
- using namespace std;
- int compare (const void *a, const void *b) {
- return ( *(int*)a - *(int*)b );
- }
- int main()
- {
- int x, n;
- int cent[1000001];
- int cont;
- int menor, maior;
- int size;
- int cont3;
- int diferenca;
- bool achou;
- while (scanf ("%d %d", &x, &n) != EOF) {
- x *= 10000000;
- size = 0;
- achou = false;
- menor = 0;
- maior = 0;
- for (int i = 0; i < n; i++) {
- scanf("%d", &cont);
- cent[i] = cont;
- }
- qsort(cent, n, sizeof(int), compare);
- size = (n-1);
- cont3 = 0;
- for (int i = size; i > cont3; i--) {
- if (cent[i] + cent[cont3] == x) {
- maior = cent[i];
- menor = cent[cont3];
- break;
- } else if (cent[i] + cent[cont3] < x) {
- cont3++;
- i = size+1;
- }
- }
- if (!menor && !maior) {
- printf("PERIGO\n");
- } else {
- printf("SIM %d %d\n", menor, maior);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement