QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#413063#6564. Frequent FlierLspeed#RE 2ms6100kbC++143.0kb2024-05-17 01:59:332024-05-17 01:59:33

Judging History

你现在查看的是最新测评结果

  • [2024-05-17 01:59:33]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:6100kb
  • [2024-05-17 01:59:33]
  • 提交

answer

#include <iostream>     // Input/output stream objects
#include <fstream>      // File stream objects
#include <sstream>      // String stream objects
#include <iomanip>      // Input/output manipulators
#include <string>       // String class and functions
#include <vector>       // Dynamic array
#include <list>         // Doubly linked list
#include <set>          // Set container
#include <map>          // Map container
#include <queue>        // Queue container
#include <stack>        // Stack container
#include <algorithm>    // Algorithms on sequences (e.g., sort, find)
#include <cmath>        // Mathematical functions
#include <climits>      // LLONG_MAX, LLONG_MIN
#include <ctime>        // Date and time functions
#include <cstdlib>      // General purpose functions (e.g., memory management)
#include <cstring>      // C-style string functions
#include <cctype>       // Character classification functions
#include <cassert>      // Assert function for debugging
#include <exception>    // Standard exceptions
#include <functional>   // Function objects
#include <iterator>     // Iterator classes
#include <limits>       // Numeric limits
#include <locale>       // Localization and internationalization
#include <numeric>      // Numeric operations (e.g., accumulate)
#include <random>       // Random number generators
#include <stdexcept>    // Standard exception classes
#include <typeinfo>     // Runtime type information
#include <utility>      // Utility components (e.g., std::pair)
#include <bitset>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < (b); i++)
#define FORE(i, a, b) for(int i = a; i <= (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define x first 
#define y second
#define mp make_pair
#define PI 3.141592653
#define compress(coord) sort(all(coord)), coord.resize(unique(all(coord)) - coord.begin())
const double eps = 1e-9; // x < eps (x <= 0) x < -eps (x < 0)
const ll inf = LLONG_MAX;

struct dqq {
    int mon;
    ll free;
};
const int N = 2e5 + 10;
int n, m, k;
vector<ll> fi(N), paid(N);
deque<dqq> dq;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> m >> k;
    FORE (i, 1, n) cin >> fi[i];

    ll sumpaid = 0;
    FORE (i, 1, n) {
        while (!dq.empty() && i - dq.front().mon >= k) dq.pop_front();
        ll topaid = max(k - sumpaid, 0LL);
        if (topaid < fi[i]) {
            paid[i] = topaid;
            dq.push_back({i, fi[i] - paid[i]});
        }
        else {
            paid[i] = fi[i];
            topaid -= fi[i];
            while (!dq.empty() && topaid > 0) {
                ll fixpaid = min(topaid, dq.back().free);
                sumpaid += fixpaid;
                paid[dq.back().mon] += fixpaid;
                dq.back().free -= fixpaid; topaid -= fixpaid;
                if (dq.back().free == 0) dq.pop_back();
            }
        }
        sumpaid += paid[i] - paid[i-k+1];
    }
    ll ans = 0;
    FORE (i, 1, n) ans += paid[i];
    cout << ans << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6100kb

input:

8 3 2
3
1
4
1
5
9
2
6

output:

8

result:

ok single line: '8'

Test #2:

score: -100
Runtime Error

input:

200000 2467 999931035
182548858
69876218
33328350
919486767
739850600
948199964
392292320
39077742
366752074
917496841
246661698
37219034
56677740
188278971
965701828
28059790
13200243
825730775
542597589
320715170
939054378
470563899
914247467
990100491
290827128
903662394
611104879
18631185
412134...

output:


result: