QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#585 | #376152 | #6823. Coffee Overdose | zhutianrui | zhouqixuan | Failed. | 2024-04-04 07:58:03 | 2024-04-04 07:58:03 |
Details
Extra Test:
Invalid Input
input:
1 00 00
output:
result:
FAIL Expected integer, but "00" found (test case 0, stdin, line 2)
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376152 | #6823. Coffee Overdose | zhouqixuan | AC ✓ | 19ms | 3948kb | C++14 | 565b | 2024-04-03 21:58:03 | 2024-04-08 20:50:09 |
answer
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
int n,m;
LL calc1(int n,int m){return (LL)n*(n-1)/2*m-(LL)(m-1)*m/2*n;}
LL calc2(int n,int m){return (LL)n*(n-1)/2*m-(LL)(m+1)*m/2*n;}
void calc(){
scanf("%d%d",&n,&m);
int k=min(m/2,n/m);
LL ans1=calc1(m,k);
k=(n-1)/m;
int r=n-k*m;
LL ans2=calc2(m,k)+(LL)m*r-(LL)r*(r+1)/2;
printf("%lld\n",max(ans1,ans2)+(LL)n*(n+1)/2);
return;
}
int main(){
int T;
scanf("%d",&T);
while(T--) calc();
return 0;
}