When I run this C++ code I got Runtime error 'SIGFPE' on Codechef. How to fix this problem?

104 views Asked by At

/* When I run this C++ code I got Runtime error 'SIGFPE' on Codechef. How to fix this problem?

Explanation

Test case 1 : Optimal filling is [5,0,5,0,5,0,5,0,5,0]

Test case 2 : Optimal filling is [6,6,5,6,6,0,6,6]

Test case 3 : Optimal filling is [2,1,2]. */

#include <bits/stdc++.h>
#include <iostream>
#include <array>
using namespace std;
int main()
{
   int T;
   cin >> T;
   while (T--)
   {
       int n, m;
       cin >> n >> m;
       int arr[n+1];
       memset(arr,0,(n+1)*sizeof(int));

       int x[m], y[m];
       for (int i = 0; i < m; i++)
       {
           cin >> x[i] >> y[i];
       }

       vector<pair<int, int>> myvector;
       for (int i = 0; i < m; i++) {
           myvector.push_back(make_pair(x[i], y[i]));
       }

       sort(myvector.begin(), myvector.end());
       int j=0;
       int i=1;
       do
       {
          int i=1;
          do
           {
               if (i % myvector[j].second != 0)
               {
                   arr[i] = myvector[j].first;
               }
               i++;
           }while (i<=n);
           j++;
       }while(j<m);

       int sum = 0;
       for (int i : arr)
       {
           sum += i;
       }
       cout << sum << endl;
   }
   return 0;
}
0

There are 0 answers