You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
775 B
C++

#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
void getint(int &x)
{
int ch = x = 0;
while (!isdigit(ch = getchar()))
;
for (; isdigit(ch); ch = getchar())
x = x * 10 + ch - '0';
}
const int N = 105;
int a[N], p[N], dp[N];
int main()
{
int T, c;
getint(T);
while (T--)
{
getint(c);
for (int i = 1; i <= c; i++)
getint(a[i]), getint(p[i]), a[i] += a[i - 1];
for (int i = 1; i <= c; i++)
{
dp[i] = (a[i] - a[i - 1] + 10) * p[i] + dp[i - 1];
for (int j = 0; j < i; j++)
dp[i] = min(dp[i], dp[j] + (a[i] - a[j] + 10) * p[i]);
}
printf("%d\n", dp[c]);
}
return 0;
}