I am getting this error on compiling :
prog.cpp:40:17: error: assignment of read-only location ‘p.std::_Rb_tree_const_iterator<_Tp>::operator*<int>()’
           *p=-1;  
It has something to do with assignment of a numerical constant to an iterator. Any other way in which I can assign some value to an iterator to update it.
CODE:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int arr[n];
        multiset<int> m;
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
            m.insert(arr[i]);
        }
        int sum = 0;
        for (auto it = m.rbegin(); it != m.rend(); it++) {
            if (*it > 0) {
                int x = *it;
                sum += x;
                auto p = m.find(x - 1);
                if (p != m.end()) {
                    *p = -1;
                }
            }
        }
        cout << sum << endl;
    }
    return 0;
}
 
    