Submission #1040467

# Submission time Handle Problem Language Result Execution time Memory
1040467 2024-08-01T05:19:44 Z 비요뜨(#11041) Tricks of the Trade (CEOI23_trade) C++17
20 / 100
8000 ms 164008 KB
#include <bits/stdc++.h>
using namespace std;

int n,k;
long long c[250000];
long long s[250000];
typedef pair<long long,int> P;
int chk[250000];
int save[250000];
vector<int> put[250005];
vector<int> er[250005];

int main() {
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++) {
        scanf("%lld",&c[i]);
    }
    for(int i=0;i<n;i++) {
        scanf("%lld",&s[i]);
    }
    int l=-1;
    int r=-1;
    long long ret=-1e18;
    for(int i=0;i<n;i++) {
        priority_queue<long long,vector<long long>,greater<long long>> pq1;
        long long sum=0;
        long long ps=0;
        for(int j=i;j<n;j++) {
            sum+=c[j];
            pq1.push(s[j]);
            ps+=s[j];
            if (pq1.size()>k) {
                long long one=pq1.top();
                pq1.pop();
                ps-=one;
            }
            if (j-i>=k-1&&ps-sum>ret) {
                l=i;
                r=j;
                ret=ps-sum;
            }
        }
    }
    printf("%lld\n",ret);
    int cnt=0;
    for(int i=0;i<n;i++) {
        priority_queue<long long,vector<long long>,greater<long long>> pq1;
        long long sum=0;
        long long ps=0;
        for(int j=i;j<n;j++) {
            sum+=c[j];
            pq1.push(s[j]);
            ps+=s[j];
            if (pq1.size()>k) {
                long long one=pq1.top();
                pq1.pop();
                ps-=one;
            }
            if (j-i>=k-1&&ps-sum==ret) {
                put[i].push_back(pq1.top());
                er[j+1].push_back(pq1.top());
            }
        }
    }
    multiset<long long> st;
    for(int i=0;i<n;i++) {
        for(int j=0;j<put[i].size();j++) {
            st.insert(put[i][j]);
        }
        for(int j=0;j<er[i].size();j++) {
            st.erase(st.find(er[i][j]));
        }
        if (!st.empty()&&s[i]>=*st.begin()) {
            chk[i]=1;
        }
    }
    for(int i=0;i<n;i++) {
        printf("%d",chk[i]);
    }
    return 0;
}

Compilation message

trade.cpp: In function 'int main()':
trade.cpp:32:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |             if (pq1.size()>k) {
      |                 ~~~~~~~~~~^~
trade.cpp:54:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |             if (pq1.size()>k) {
      |                 ~~~~~~~~~~^~
trade.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j=0;j<put[i].size();j++) {
      |                     ~^~~~~~~~~~~~~~
trade.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int j=0;j<er[i].size();j++) {
      |                     ~^~~~~~~~~~~~~
trade.cpp:21:9: warning: variable 'l' set but not used [-Wunused-but-set-variable]
   21 |     int l=-1;
      |         ^
trade.cpp:22:9: warning: variable 'r' set but not used [-Wunused-but-set-variable]
   22 |     int r=-1;
      |         ^
trade.cpp:45:9: warning: unused variable 'cnt' [-Wunused-variable]
   45 |     int cnt=0;
      |         ^~~
trade.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
trade.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld",&c[i]);
      |         ~~~~~^~~~~~~~~~~~~~
trade.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%lld",&s[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16984 KB Output is correct
2 Correct 2 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16988 KB Output is correct
2 Correct 2 ms 16984 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 2 ms 17024 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 2 ms 16988 KB Output is correct
9 Correct 2 ms 16988 KB Output is correct
10 Correct 4 ms 16984 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16988 KB Output is correct
2 Correct 2 ms 16984 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 2 ms 17024 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 2 ms 16988 KB Output is correct
9 Correct 2 ms 16988 KB Output is correct
10 Correct 4 ms 16984 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 2 ms 16988 KB Output is correct
13 Correct 2 ms 16988 KB Output is correct
14 Correct 2 ms 16984 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 2 ms 16988 KB Output is correct
18 Correct 2 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 17040 KB Output is correct
21 Correct 3 ms 16984 KB Output is correct
22 Correct 2 ms 16996 KB Output is correct
23 Correct 508 ms 17132 KB Output is correct
24 Correct 340 ms 16992 KB Output is correct
25 Correct 1085 ms 17244 KB Output is correct
26 Correct 922 ms 16988 KB Output is correct
27 Correct 851 ms 164008 KB Output is correct
28 Correct 263 ms 17012 KB Output is correct
29 Correct 817 ms 17232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16988 KB Output is correct
2 Execution timed out 8086 ms 18012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16988 KB Output is correct
2 Execution timed out 8086 ms 18012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16984 KB Output is correct
2 Correct 2 ms 16984 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 2 ms 16984 KB Output is correct
5 Correct 2 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 2 ms 17024 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 2 ms 16988 KB Output is correct
11 Correct 2 ms 16988 KB Output is correct
12 Correct 4 ms 16984 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 2 ms 16988 KB Output is correct
15 Correct 2 ms 16988 KB Output is correct
16 Correct 2 ms 16984 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 2 ms 16988 KB Output is correct
20 Correct 2 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 17040 KB Output is correct
23 Correct 3 ms 16984 KB Output is correct
24 Correct 2 ms 16996 KB Output is correct
25 Correct 508 ms 17132 KB Output is correct
26 Correct 340 ms 16992 KB Output is correct
27 Correct 1085 ms 17244 KB Output is correct
28 Correct 922 ms 16988 KB Output is correct
29 Correct 851 ms 164008 KB Output is correct
30 Correct 263 ms 17012 KB Output is correct
31 Correct 817 ms 17232 KB Output is correct
32 Correct 2 ms 16988 KB Output is correct
33 Execution timed out 8086 ms 18012 KB Time limit exceeded
34 Halted 0 ms 0 KB -