Cod sursa(job #3240538)

Utilizator razvanmrt_06Mariuta Razvan razvanmrt_06 Data 16 august 2024 11:02:07
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("ceva.in");
ofstream fout("ceva.out");

const int Nmax = 20001;
int n, val, igood, jgood;
pair <int, int> a[Nmax];

int main()
{
    fin >> n >> val;
    for(int i = 0; i < n; i++){
        fin >> a[i].first;
        a[i].second = i;
    }

    sort(a, a+n);

    int i = 0;
    int j = n-1;
    while(i < j){
        int suma = a[i].first + a[j].first;
        if(suma == val){
            igood = a[i].second;
            jgood = a[j].second;
            break;
        }
        else if(suma < val){
            i++;
        }
        else{
            j--;
        }
    }

    cout << igood << ' ' << jgood;

    return 0;
}