QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742588#9529. Farm Managementzwu2021016337WA 1ms5764kbC++202.7kb2024-11-13 16:51:582024-11-13 16:51:58

Judging History

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

  • [2024-11-13 16:51:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5764kb
  • [2024-11-13 16:51:58]
  • 提交

answer

#include <bits/stdc++.h> // By Lucky Ox
#define int long long
#define endl "\n"
#define pii pair<int, int>
#define PI atan(1.0) * 4
using namespace std;
using i128 = __int128;
typedef unsigned long long ull;
const int mod = LONG_LONG_MAX, INF = 0x3f3f3f3f3f3f3f3f;
int P(int x, int p){ return (x % p + p) % p; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int len_10(int x) { int len = 0; while(x) { x /= 10; len ++ ; } return len; }
int q_pow(int a, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * a % p; k >>= 1; a = a * a % p; } return res; }
int to_int(string s) { int val = 0; for(int i = 0; i < (int)s.size(); i ++ ){val *= 10; val += s[i] - '0';}return val;}//注意:s是空串也会返回0
i128 read() { i128 x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar(); } return x; } //i128输入
void print(i128 x) {if(x > 9) print(x / 10); putchar(x % 10 + '0'); }//i128输出
//用__lg()来求一个数二进制下的位数 返回的len 表示这个数是[0, 1, ...., len] 比如10 __lg(10) = 3, 1010 [3, 2, 1, 0]
//__builtin_popcountll(int x) 求二进制下x中1的数量 __buitlin_ctzll(int x) 求二进制下末尾0的个数
//(n & (1 << i))的值可能会是1, 2, 4...... (n >> i) & 1的值一定是1
//将x转换成[1, n]中对应的数 (x - 1) % n + 1

const int N = 1e5 + 10;
int n, m;
struct node {
    int w, l, r;
    bool operator < (const node &that) const {
        return w < that.w;
    } 
}a[N];
struct ox {
    int t, sum;
} pre[N], suf[N];
void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ ) {
        int w, l, r;
        cin >> w >> l >> r;
        a[i] = {w, l, r};
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i ++ ) pre[i].t = a[i].l + pre[i - 1].t, pre[i].sum = a[i].w * a[i].l + pre[i - 1].sum;
    for(int i = n; i >= 1; i -- ) suf[i].t = a[i].r + suf[i + 1].t, suf[i].sum = a[i].w * a[i].r + suf[i + 1].sum;

    int ans = 0;
    for(int i = 1; i <= n; i ++ ) {
        int res = 0, t = m;

        res += pre[i - 1].sum;
        t -= pre[i - 1].t;

        int l = i + 1, r = n;
        while(l <= r) {
            int mid = (l + r) >> 1;
            if(suf[mid].t >= t) l = mid + 1;
            else r = mid - 1;
        }
        res += suf[r].sum;
        t -= suf[r].t;
        res += a[r - 1].w * t;

        ans = max(ans, res);
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    //cin >> T;
    while (T -- ) solve();
    return 0;
}
/*
5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5764kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5668kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

40483937

result:

wrong answer 1st lines differ - expected: '35204500', found: '40483937'