제출 #545556

#제출 시각아이디문제언어결과실행 시간메모리
545556LoboCake 3 (JOI19_cake3)C++17
0 / 100
2 ms340 KiB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e3+10;

int n, m, c[maxn], v[maxn], ccval[maxn];
vector<int> vec[maxn];

void solve() {
    cin >> n >> m;

    vector<int> cc;
    for(int i = 1; i <= n; i++) {
        cin >> v[i] >> c[i];
        cc.pb(c[i]);
    }
    sort(all(cc));
    cc.erase(unique(all(cc)),cc.end());

    for(int i = 1; i <= n; i++) {
        int x = c[i];
        c[i] = upper_bound(all(cc),c[i]) - cc.begin();
        ccval[c[i]] = x;
        vec[c[i]].pb(v[i]);
    }

    int ans = -inf;
    for(int i = 1; i <= n; i++) {
        multiset<int> st1,st2;
        int sm = 0;
        for(int j = i; j <= n; j++) {
            for(auto x : vec[j]) {
                st2.insert(x);
            }

            while(st1.size() < m && st2.size()) {
                auto it = st2.end();
                it--;
                int x = *it;
                st1.insert(x);
                sm+= x;
                st2.erase(st2.find(x));
            }

            while(st1.size() && st2.size()) {
                auto it1 = st1.begin();
                auto it2 = st2.end(); it2--;

                if(*it1 >= *it2) break;
                else {
                    sm+= *it2 - *it1;
                    int x = *it1;
                    int y = *it2;
                    st1.erase(st1.find(x));
                    st1.insert(y);
                    st2.erase(st2.find(y));
                    st2.insert(x);
                } 
            }

            if(st1.size() >= m) ans = max(ans, sm - 2*ccval[j] + 2*ccval[i]);
            // cout << ccval[i] << " " << ccval[j] << " " << sm << endl;
        }
    }

    cout << ans << endl;


}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    
    int tt = 1;
    // cin >> tt;
    int t = 1;
    while(tt--) {
        solve();
    }

}

컴파일 시 표준 에러 (stderr) 메시지

cake3.cpp: In function 'void solve()':
cake3.cpp:47:30: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   47 |             while(st1.size() < m && st2.size()) {
      |                   ~~~~~~~~~~~^~~
cake3.cpp:72:27: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   72 |             if(st1.size() >= m) ans = max(ans, sm - 2*ccval[j] + 2*ccval[i]);
      |                ~~~~~~~~~~~^~~~
cake3.cpp: In function 'int32_t main()':
cake3.cpp:90:9: warning: unused variable 't' [-Wunused-variable]
   90 |     int t = 1;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...