第三题排序即可,大的先做。能做就越后面做越好,做不了就不做了 using namespace std; int DP[1005]; struct Task {     int t;     int value;     bool operator<(const Task &src) const     {         if (value != src.value)             return value > src.value;         return t > src.t;     } }; int main() {     int T;     cin >> T;     while (T--)     {         vector<int> occ(1001);         int n;         cin >> n;         vector<Task> v(n);         for (auto &ele : v)             cin >> ele.t;         for (auto &ele : v)             cin >> ele.value;         sort(v.begin(), v.end());         int ans = 0;         for (const auto &t : v)         {             ans -= t.value;             int Tdes = t.t;             while (Tdes >= 1)             {                 if (occ[Tdes] == 0)                 {                     occ[Tdes] = 1;                     ans += t.value;                     break;                 }                 Tdes--;             }         }         cout << -ans << endl;     }     return 0; }