QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#674863 | #9528. New Energy Vehicle | ytck# | WA | 0ms | 3776kb | C++17 | 1.7kb | 2024-10-25 17:36:09 | 2024-10-25 17:36:10 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
#define endl '\n'
#define PII pair<int, int>
#define int long long
//#define int __int128
using namespace std;
inline int read();
inline void write(int x);
const int N = 1e5 + 10, M = 2e3 + 10, mod = 998244353, inf = 1e18, base = 131;
const double eps = 1e-7;
int n, m;
void solve(){
cin >> n >> m;
vector<int> p(n + 10, 0);
vector<PII> f(m + 10, {0, 0});
int sum = 0, res;
for(int i = 1; i <= n; i++){
cin >> p[i];
sum += p[i];
}
res = sum;
for(int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
f[i] = {a, b};
}
int dv = 0;
for(int i = 1; i <= m; i++){
int b = f[i].second;
int len = f[i].first - f[i - 1].first;
if(len > p[b]){
dv += (len - p[b]);
if(dv > sum){
dv -= (len - p[b]);
cout << f[i - 1].first + (sum - dv);
return;
}
}
else{
int d = p[b] - len;
res += min(dv, d);
dv -= min(dv, d);
}
}
cout << f[m].first + (sum - dv) << endl;
}
signed main() {
IOS;
int T = 1;
cin >> T;
while (T--){
solve();
}
}
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar('0' + x % 10);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
12 9
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3776kb
input:
6 3 2 2 2 2 6 1 7 1 2 2 3 3 2 1 6 2 2 3 2 2 5 1 7 2 9 1 2 2 3 3 2 1 6 2 1 1 999999999 1000000000 1 1 1 1000000000 1000000000 1
output:
10 11 10 11 1999999998 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'