QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#413064 | #6564. Frequent Flier | Lspeed# | AC ✓ | 16ms | 11628kb | C++14 | 3.2kb | 2024-05-17 02:10:44 | 2024-05-17 02:10:45 |
Judging History
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(2*N), paid(2*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+m-1) {
while (!dq.empty() && i - dq.front().mon >= m) dq.pop_front();
// cout << "I: " << i << "SUM PAID " << m << " months: " << sumpaid << endl;
ll topaid = max(k - sumpaid, 0LL);
// cout << "TO PAID: " << topaid << endl;
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();
}
}
// cout << "I PAID: " << paid[i] << endl;
sumpaid += paid[i] - (i-m+1 >= 0 ? paid[i-m+1] : 0);
}
ll ans = 0;
FORE (i, 1, n) ans += paid[i];
cout << ans << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9196kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 11ms
memory: 9252kb
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:
82994275905
result:
ok single line: '82994275905'
Test #3:
score: 0
Accepted
time: 3ms
memory: 9248kb
input:
1 200000 999959273 1255319
output:
1255319
result:
ok single line: '1255319'
Test #4:
score: 0
Accepted
time: 13ms
memory: 11628kb
input:
200000 118880 996878327 993340390 999483057 808153702 337349872 863222189 7495963 995920883 12950768 958082368 993215196 967152406 1388062 949959944 836952150 964071667 5291 139115263 958470154 51295691 175385 925242139 995685554 10895812 12563 55482 479983443 42805 996241239 6228013 302633329 10331...
output:
2990634981
result:
ok single line: '2990634981'
Test #5:
score: 0
Accepted
time: 16ms
memory: 9252kb
input:
200000 15 44049967 999927791 29351 999894087 687373343 518282902 19725626 452930 6701 999697321 27032796 5498 259987 999999980 485673990 805879 315651507 166801295 189865616 999910671 6203805 978801777 41916529 942904087 997589912 17146790 922137016 444882952 999884603 999926345 938979650 18597283 9...
output:
598769574112
result:
ok single line: '598769574112'