Submission #19152306
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ld long double
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
//////////////////////////////////////////////////////// By: Umang Srivastava
lli extgcd(lli a, lli b, lli *x , lli *y)
{
if(a==0)
{
*x=0;
*y=1;
return b;
}
lli x1 , y1;
lli gcd = extgcd(b%a , a , &x1 , &y1);
*x= y1 - (b/a) * x1;
*y=x1;
return gcd;
}
lli modinv(lli a, lli m)
{
lli x,y;
lli g = extgcd(a,m,&x,&y);
if(g!=1)
return -1;
return (x%m+m)%m;
}
// lli moddiv(lli a, lli b, lli m)
// {
// a=a%m;
// lli inv = modinv(b,m);
// if(inv!=-1)
// return ((a*inv + m)%m);
// else
// return -1;
// }
// lli binpow(lli a, lli b, lli m)
// {
// lli res=1;
// a=a%m;
// while(b>0)
// {
// if(b & 1)
// {
// res = (res * a)%m;
// }
// b=b>>1;
// a=(a*a)%m;
// }
// return res;
// }
// lli gcd(lli a, lli b)
// {
// // if(b<a)
// // {
// // lli t=a;
// // a=b;
// // b=t;
// // }
// if(a==0)
// return b;
// return gcd(b%a,a);
// }
// lli fac[1000005];
// void calcfac(lli m)
// {
// fac[0]=1;
// for(lli i=1;i<=1000001;i++)
// {
// fac[i]=(fac[i-1]*i)%m;
// }
// }
// lli ncr(lli n,lli r,lli m)
// {
// if(r==0 || r==n)
// return 1;
// return (((fac[n]*binpow(fac[r],m-2,m))%m)*(binpow(fac[n-r],m-2,m)))%m;
// }
/////////////////////////////////////////////////////////
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
t=1;
a=b=0;
c=d=0;
// cin>>t;
while(t--)
{
cin>>n;
vector<pair<lli,lli>>ar;
for(i=0;i<n;i++)
{
cin>>a>>b;
ar.pb({a+b,a});
}
if(n==1)
{
cout<<1<<endl;
return 0;
}
sort(ar.begin(),ar.end());reverse(ar.begin(),ar.end());
lli tak[n]={0};
lli aok[n+1]={0};
tak[0]=ar[0].ff;
aok[n]=0;
aok[n-1]=ar[n-1].ss;
for(i=1;i<n;i++)
{
tak[i]=tak[i-1] + ar[i].ff;
}
for(i=1;i<=n-1;i++)
{
aok[n-1-i]=aok[n-i] + ar[n-1-i].ss;
}
for(i=0;i<n;i++)
{
if(tak[i]>aok[i+1])
break;
}
// for(i=0;i<n;i++)
// {
// cout<<tak[i]<<" "<<aok[i]<<endl;
// }
cout<<i+1<<endl;
}
}
Submission Info
Submission Time |
|
Task |
D - Choose Me |
User |
Stark_3000 |
Language |
C++ (GCC 9.2.1) |
Score |
0 |
Code Size |
2688 Byte |
Status |
WA |
Exec Time |
61 ms |
Memory |
9432 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:105:9: warning: unused variable ‘m’ [-Wunused-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^
./Main.cpp:105:13: warning: unused variable ‘j’ [-Wunused-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^
./Main.cpp:105:15: warning: unused variable ‘k’ [-Wunused-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^
./Main.cpp:105:17: warning: unused variable ‘tc’ [-Wunused-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^~
./Main.cpp:105:26: warning: variable ‘c’ set but not used [-Wunused-but-set-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^
./Main.cpp:105:30: warning: unused variable ‘x’ [-Wunused-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^
./Main.cpp:105:32: warning: unused variable ‘y’ [-Wunused-variable]
105 | lli n,m,i,j,k,tc,t,a,b,c,d,x,y;
| ^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
01_small.txt, 02_small.txt, 03_small.txt, 04_small.txt, 05_small.txt, 06_small.txt, 07_small.txt, 08_small.txt, 09_small.txt, 10_small.txt, 11_small.txt, 12_small.txt, 13_small.txt, 14_small.txt, 15_small.txt, 16_large.txt, 17_large.txt, 18_large.txt, 19_large.txt, 20_large.txt, 21_large.txt, 22_large.txt, 23_large.txt, 24_large.txt, 25_large.txt, 26_max.txt, 27_max.txt, 28_max.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name |
Status |
Exec Time |
Memory |
01_small.txt |
AC |
5 ms |
3560 KiB |
02_small.txt |
AC |
2 ms |
3572 KiB |
03_small.txt |
AC |
2 ms |
3452 KiB |
04_small.txt |
AC |
2 ms |
3612 KiB |
05_small.txt |
AC |
2 ms |
3552 KiB |
06_small.txt |
AC |
3 ms |
3580 KiB |
07_small.txt |
AC |
2 ms |
3568 KiB |
08_small.txt |
AC |
2 ms |
3608 KiB |
09_small.txt |
AC |
3 ms |
3612 KiB |
10_small.txt |
AC |
3 ms |
3452 KiB |
11_small.txt |
AC |
2 ms |
3552 KiB |
12_small.txt |
AC |
2 ms |
3492 KiB |
13_small.txt |
AC |
1 ms |
3448 KiB |
14_small.txt |
AC |
3 ms |
3508 KiB |
15_small.txt |
AC |
4 ms |
3652 KiB |
16_large.txt |
WA |
34 ms |
6032 KiB |
17_large.txt |
WA |
59 ms |
8936 KiB |
18_large.txt |
WA |
23 ms |
5064 KiB |
19_large.txt |
WA |
23 ms |
4880 KiB |
20_large.txt |
WA |
21 ms |
5216 KiB |
21_large.txt |
WA |
20 ms |
4704 KiB |
22_large.txt |
WA |
17 ms |
4440 KiB |
23_large.txt |
AC |
4 ms |
3672 KiB |
24_large.txt |
WA |
54 ms |
8124 KiB |
25_large.txt |
WA |
61 ms |
9320 KiB |
26_max.txt |
AC |
48 ms |
9376 KiB |
27_max.txt |
AC |
50 ms |
9372 KiB |
28_max.txt |
AC |
53 ms |
9432 KiB |
sample_01.txt |
AC |
3 ms |
3608 KiB |
sample_02.txt |
AC |
2 ms |
3608 KiB |
sample_03.txt |
AC |
2 ms |
3492 KiB |