Submission #579129

# Submission time Handle Problem Language Result Execution time Memory
579129 2022-06-18T12:05:16 Z lcj Two Dishes (JOI19_dishes) C++17
0 / 100
169 ms 20592 KB
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int n, m;

struct Dish {
    ll a, s, p;
};
vector<Dish> d1, d2;
vector<ll> p1, p2, po1, po2;

ll getTime(int i1, int i2) {
    return p1[i1]+p2[i2];
}


void solve() {
    cin >> n >> m;
    ll a, s, p;
    p1.assign(n+1, 0);
    p2.assign(m+1, 0);
    po1.assign(n+1, 0);
    po2.assign(n+1, 0);
    int t1, t2;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> s >> p;
        Dish dd = Dish {a, s, p};
        d1.push_back(dd);
        p1[i+1] = p1[i]+a;
        po1[i+1] = po1[i]+p;
        t1 = s;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> a >> s >> p;
        Dish dd = Dish {a, s, p};
        d2.push_back(dd);
        p2[i+1] = p2[i]+a;
        po2[i+1] = po2[i]+p;
        t2 = s;
    }
    if (t1 > t2) {
        swap(t1, t2);
        swap(d1, d2);
        swap(p1, p2);
        swap(po1, po2);
        swap(n, m);
    }
    ll cmax = 0; bool iset = 0;
    for (int i = 0; i <= n; i++)
    {
        if (p1[i] > t1) continue;
        int lo = 0;int hi = m;
        if (p1[i]+p2[hi] <= t2) {
            lo = hi;
            goto f1;
        }
        while (hi-lo > 1)
        {
            int mid = (lo+hi)/2;
            if (p1[i]+p2[mid] > t2) {
                hi = mid;
            }
            else {
                lo = mid;
            }
        }
f1:
        if (!iset) cmax = po1[i]+po2[lo];
        cmax = max(cmax, po1[i]+po2[lo]);
        iset = 1;
    }
    cout << cmax << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

Compilation message

dishes.cpp: In function 'void solve()':
dishes.cpp:58:19: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   58 |         if (p1[i] > t1) continue;
dishes.cpp:60:26: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   60 |         if (p1[i]+p2[hi] <= t2) {
dishes.cpp:67:31: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   67 |             if (p1[i]+p2[mid] > t2) {
dishes.cpp:48:5: warning: 't2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     if (t1 > t2) {
      |     ^~
dishes.cpp:48:5: warning: 't1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 20592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 20592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 20592 KB Output isn't correct
2 Halted 0 ms 0 KB -