class Solution
{
public:
long long maxSpending(vector<vector<int>>& values)
{
int idx[500] = {0};
for (int i = 0; i < values.size(); i++)
{
idx[i] = values[0].size() - 1;
}
long long ans = 0;
long long times = 1;
while(1)
{
int minIdx = -1;
for (int i = 0; i < values.size(); i++)
{
if (idx[i] < 0)
{
continue;
}
if (minIdx == -1 || values[i][idx[i]] < values[minIdx][idx[minIdx]])
{
minIdx = i;
}
}
if (minIdx == -1)
{
break;
}
ans += values[minIdx][idx[minIdx]--] * (times++);
}
return ans;
}
};
标签:开销,idx,int,long,2931,values,ans,leetcode,minIdx From: https://blog.csdn.net/lyx142606/article/details/144436238