Submission #278006

# Submission time Handle Problem Language Result Execution time Memory
278006 2020-08-21T08:33:05 Z 반딧불(#5119) Shopping Plans (CCO20_day2problem3) C++17
0 / 25
2511 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, vector<int> > pivi;

int n, m, k;
vector<ll> arr[200002];
priority_queue<pivi> pq;
ll ans[200002];
set<vector<int> > st;
ll sum = 0;

int main(){
    scanf("%d %d %d", &n, &m, &k);
    for(int i=1; i<=n; i++){
        int x; ll y;
        scanf("%d %lld", &x, &y);
        arr[x].push_back(y);
    }
    for(int i=1; i<=m; i++){
        int x, y;
        scanf("%d %d", &x, &y);
    }

    for(int i=1; i<=m; i++) sort(arr[i].begin(), arr[i].end());
    for(int i=1; i<=m; i++){
        if(arr[i].empty()){
            while(k--) printf("-1\n");
            return 0;
        }
        sum += arr[i][0];
    }

    pq.push({-sum, vector<int>(m, 0)});
    st.insert(vector<int>(m, 0));

    for(int d=1; d<=k; d++){
        if(pq.empty()) break;
        auto tmp = pq.top(); pq.pop();
//        for(int i=0; i<m; i++) printf("%d ", tmp.second[i]); puts("");
        ans[d] = -tmp.first;
        for(int i=0; i<m; i++){
            if(tmp.second[i] == (int)arr[i+1].size()-1) continue;
            tmp.second[i]++;
            if(st.find(tmp.second) == st.end())
                st.insert(tmp.second), pq.push(make_pair(-(-tmp.first + arr[i+1][tmp.second[i]] - arr[i+1][tmp.second[i]-1]), tmp.second));
            tmp.second[i]--;
        }
    }

    for(int d=1; d<=k; d++){
        printf("%lld\n", ans[d] ? ans[d] : -1);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |         scanf("%d %lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2511 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2374 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2511 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 5632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2511 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -