Submission #1040458

# Submission time Handle Problem Language Result Execution time Memory
1040458 2024-08-01T04:37:32 Z 비요뜨(#11041) Tricks of the Trade (CEOI23_trade) C++17
10 / 100
8000 ms 5984 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];

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<P,vector<P>,greater<P>> pq1;
        long long sum=0;
        long long ps=0;
        for(int j=i;j<n;j++) {
            sum+=c[j];
            pq1.push(P(s[j],j));
            save[j]=cnt;
            ps+=s[j];
            if (pq1.size()>k) {
                P one=pq1.top();
                pq1.pop();
                ps-=one.first;
                if (one.second!=j&&save[one.second]<cnt) {
                    chk[one.second]=1;
                }
            }
            if (j-i>=k-1&&ps-sum==ret) {
                cnt++;
            }
        }
        while (!pq1.empty()) {
                P one=pq1.top();
                pq1.pop();
                if (save[one.second]<cnt) {
                    chk[one.second]=1;
                }
        }
    }
    for(int i=0;i<n;i++) {
        printf("%d",chk[i]);
    }
    return 0;
}

Compilation message

trade.cpp: In function 'int main()':
trade.cpp:30: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]
   30 |             if (pq1.size()>k) {
      |                 ~~~~~~~~~~^~
trade.cpp:53:27: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int>, std::vector<std::pair<long long int, int> >, std::greater<std::pair<long long int, int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |             if (pq1.size()>k) {
      |                 ~~~~~~~~~~^~
trade.cpp:19:9: warning: variable 'l' set but not used [-Wunused-but-set-variable]
   19 |     int l=-1;
      |         ^
trade.cpp:20:9: warning: variable 'r' set but not used [-Wunused-but-set-variable]
   20 |     int r=-1;
      |         ^
trade.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
trade.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%lld",&c[i]);
      |         ~~~~~^~~~~~~~~~~~~~
trade.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%lld",&s[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4548 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Partially correct 2 ms 4444 KB Partially correct
10 Correct 2 ms 4444 KB Output is correct
11 Partially correct 2 ms 4444 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4548 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Partially correct 2 ms 4444 KB Partially correct
10 Correct 2 ms 4444 KB Output is correct
11 Partially correct 2 ms 4444 KB Partially correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Partially correct 1 ms 4444 KB Partially correct
21 Correct 2 ms 4444 KB Output is correct
22 Partially correct 2 ms 4444 KB Partially correct
23 Correct 1807 ms 4776 KB Output is correct
24 Correct 402 ms 4440 KB Output is correct
25 Correct 1472 ms 4440 KB Output is correct
26 Correct 1053 ms 4440 KB Output is correct
27 Correct 1131 ms 4444 KB Output is correct
28 Correct 389 ms 4536 KB Output is correct
29 Correct 1760 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Execution timed out 8090 ms 5984 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Execution timed out 8090 ms 5984 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4548 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Partially correct 2 ms 4444 KB Partially correct
12 Correct 2 ms 4444 KB Output is correct
13 Partially correct 2 ms 4444 KB Partially correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Partially correct 1 ms 4444 KB Partially correct
23 Correct 2 ms 4444 KB Output is correct
24 Partially correct 2 ms 4444 KB Partially correct
25 Correct 1807 ms 4776 KB Output is correct
26 Correct 402 ms 4440 KB Output is correct
27 Correct 1472 ms 4440 KB Output is correct
28 Correct 1053 ms 4440 KB Output is correct
29 Correct 1131 ms 4444 KB Output is correct
30 Correct 389 ms 4536 KB Output is correct
31 Correct 1760 ms 4440 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
33 Execution timed out 8090 ms 5984 KB Time limit exceeded
34 Halted 0 ms 0 KB -