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 cont2;
- int menor, maior;
- int size;
- int diferenca;
- bool achou;
- while (scanf ("%d %d", &x, &n) != EOF) {
- x *= 10000000;
- size = 0;
- cont2 = 0;
- achou = false;
- menor = 0;
- maior = 0;
- for (int i = 0; i < n; i++) {
- scanf("%d", &cont);
- if (cont < x) {
- cent[i-cont2] = cont;
- } else {
- cont++;
- }
- }
- qsort(cent, n-cont2, sizeof(int), compare);
- size = (n-cont2)/2;
- for (int i = 0; i < size; i++) {
- for (int j = (n-cont2)-1; j > i+1; j--) {
- if (cent[i] + cent[j] < x) {
- break;
- } else if (cent[i] + cent[j] == x) {
- menor = cent[i];
- maior = cent[j];
- achou = true;
- break;
- }
- }
- if (achou) break;
- }
- 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