#include <iostream>
#include <ctime>
#include <omp.h>

const int N = 10000000; // Size of arrays

void sequentialAdd(const int* a, const int* b, int* result, int size) {
    for (int i = 0; i < size; i++) {
        result[i] = a[i] + b[i];
    }
}

void parallelAdd(const int* a, const int* b, int* result, int size) {
    #pragma omp parallel for
    for (int i = 0; i < size; i++) {
        result[i] = a[i] + b[i];
    }
}

int main() {
    // Allocate dynamic arrays
    int* a = new int[N];
    int* b = new int[N];
    int* result = new int[N];

    // Initialize arrays with values
    for (int i = 0; i < N; ++i) {
        a[i] = 1;
        b[i] = 2;
    }

    // Sequential addition and timing
    clock_t startSeq = clock();
    sequentialAdd(a, b, result, N);
    clock_t endSeq = clock();
    double timeSeq = double(endSeq - startSeq) / CLOCKS_PER_SEC;
    std::cout << "Sequential addition time: " << timeSeq << " seconds\n";

    // Parallel addition and timing
    clock_t startPar = clock();
    parallelAdd(a, b, result, N);
    clock_t endPar = clock();
    double timePar = double(endPar - startPar) / CLOCKS_PER_SEC;
    std::cout << "Parallel addition time: " << timePar << " seconds\n";

    // Clean up dynamic arrays
    delete[] a;
    delete[] b;
    delete[] result;

    return 0;
}