QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288046#7750. Revenge on My BossMax_s_xaMWA 326ms8200kbC++143.1kb2023-12-21 17:15:542023-12-21 17:15:54

Judging History

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

  • [2023-12-21 17:15:54]
  • 评测
  • 测评结果:WA
  • 用时:326ms
  • 内存:8200kb
  • [2023-12-21 17:15:54]
  • 提交

answer

#include <iostream>
#include <algorithm>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 1e5 + 10;

int n, a[MAXN], b[MAXN], c[MAXN];
ll sum;

struct Data
{
    ll d, x; int id;
    bool operator < (const Data u) const
    {
        if (d <= 0 && u.d > 0) return 1;
        if (d > 0 && u.d <= 0) return 0;
        if (d <= 0 && u.d <= 0) return x - d > u.x - u.d;
        return x < u.x;
    }
}f[MAXN];

inline bool Check(ll mid)
{
    for (int i = 1; i <= n; i++) f[i].d = b[i] - a[i], f[i].x = mid / c[i] - sum, f[i].id = i;
    sort(f + 1, f + n + 1);
    ll psum = 0;
    for (int i = 1; i <= n; i++)
    {
        psum += f[i].d;
        if (psum > f[i].x) return 0; 
    }
    return 1;
}

int main()
{
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    int T;
    Read(T);
    while (T--)
    {
        Read(n);
        sum = 0;
        for (int i = 1; i <= n; i++) Read(a[i]), Read(b[i]), Read(c[i]), sum += a[i];
        ll l = 0, r = 1e17, mid, ans;
        while (l <= r)
        {
            mid = l + r >> 1ll;
            if (Check(mid)) ans = mid, r = mid - 1;
            else l = mid + 1;
        }
        Check(ans);
        for (int i = n; i >= 1; i--) cout << f[i].id << " ";
        cout << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 326ms
memory: 8200kb

input:

1
100000
581297 102863 1
742857 42686 1
676710 233271 1
443055 491162 1
442056 28240 1
769277 331752 1
8608 369730 1
495112 525554 1
787449 938154 1
441186 850694 1
84267 925450 1
740811 32385 1
834021 37680 1
257878 564126 1
90618 914340 1
239641 463103 1
40687 343062 1
587737 458554 1
103684 48666...

output:

47574 47572 47571 47569 47568 47566 47565 47564 47563 47561 47556 47554 47553 47546 67556 47539 47538 47537 47535 47534 47532 47527 47525 47524 47522 47520 47519 47518 47517 47515 47540 47630 47629 47627 47626 47622 47621 4027 47616 47614 47611 47609 47606 47605 47604 47603 47579 47601 4029 47599 47...

result:

wrong answer Wrong Answer on Case#1