/* 当我运行这个 C++ 代码时,我在 Codechef 上得到了运行时错误“SIGFPE”。如何解决这个问题?
解释
测试用例1:最佳填充是[5,0,5,0,5,0,5,0,5,0]
测试用例 2:最佳填充是 [6,6,5,6,6,0,6,6]
测试用例 3:最佳填充是 [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;
}