Submission #1052040

#TimeUsernameProblemLanguageResultExecution timeMemory
1052040dilanyanSemiexpress (JOI17_semiexpress)C++17
100 / 100
1 ms348 KiB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
//------------------Kargpefines--------------------\\ 
 
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set

void KarginSet(string name = "") {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    if (name.size()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
 
//-------------------KarginConstants------------------\\ 
 
const ll mod = 1e9 + 7;
const ll inf = 2e18;
 
//-------------------KarginCode-----------------------\\ 
 
const int N = 300006, M = 1000005;

ll s[N];

void KarginSolve() {
    ll n, m, k, a, b, c, t;
    cin >> n >> m >> k >> a >> b >> c >> t;
    for (int i = 1;i <= m;i++) cin >> s[i];
    ll ans = 0;
    ll cnt = k - m;
    if ((n - 1) * b <= t) ans++;
    pqueue<int> pq;
    for (int i = 1;i < m;i++) {
        ll time = (s[i] - 1) * b;
        if (time > t) break;
        ll ind = s[i];
        while (time <= t) {
            //ans++;
            ll l = ind, r = s[i + 1] - 1, st = ind;
            while (l <= r) {
                ll mid = (l + r) / 2;
                if ((mid - ind) * a <= t - time) {
                    l = mid + 1;
                    st = mid;
                }
                else r = mid - 1;
            }
            //ans += st - ind;
            if (ind == s[i]) {
                ans += st - ind + 1;
            }
            else if (pq.size() < k - m) {
                pq.push(-(st - ind +  1));
            }
            else {
                if (-pq.top() < st - ind + 1) {
                    pq.pop();
                    pq.push(-(st - ind + 1));
                }
                else break;
            }
            if (st + 1 < s[i + 1]) {
                time += (st + 1 - ind) * c;
                if (time > t) break;
                ind = st + 1;
            }
            else break;
        }
    }
    while (!pq.empty()) {
        ans += -pq.top();
        pq.pop();
    }
    cout << ans - 1 << '\n';
}

int main() {
    KarginSet();
    int test = 1;
    //cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0;
}

Compilation message (stderr)

semiexpress.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
semiexpress.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------Kargpefines--------------------\\
      | ^
semiexpress.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginConstants------------------\\
      | ^
semiexpress.cpp:32:1: warning: multi-line comment [-Wcomment]
   32 | //-------------------KarginCode-----------------------\\
      | ^
semiexpress.cpp: In function 'void KarginSolve()':
semiexpress.cpp:65:32: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   65 |             else if (pq.size() < k - m) {
      |                      ~~~~~~~~~~^~~~~~~
semiexpress.cpp:43:8: warning: unused variable 'cnt' [-Wunused-variable]
   43 |     ll cnt = k - m;
      |        ^~~
semiexpress.cpp: In function 'void KarginSet(std::string)':
semiexpress.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...